cifs_debug.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913
  1. /*
  2. * fs/cifs_debug.c
  3. *
  4. * Copyright (C) International Business Machines Corp., 2000,2005
  5. *
  6. * Modified by Steve French (sfrench@us.ibm.com)
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  16. * the GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  21. */
  22. #include <linux/fs.h>
  23. #include <linux/string.h>
  24. #include <linux/ctype.h>
  25. #include <linux/module.h>
  26. #include <linux/proc_fs.h>
  27. #include <asm/uaccess.h>
  28. #include "cifspdu.h"
  29. #include "cifsglob.h"
  30. #include "cifsproto.h"
  31. #include "cifs_debug.h"
  32. #include "cifsfs.h"
  33. void
  34. cifs_dump_mem(char *label, void *data, int length)
  35. {
  36. int i, j;
  37. int *intptr = data;
  38. char *charptr = data;
  39. char buf[10], line[80];
  40. printk(KERN_DEBUG "%s: dump of %d bytes of data at 0x%p\n",
  41. label, length, data);
  42. for (i = 0; i < length; i += 16) {
  43. line[0] = 0;
  44. for (j = 0; (j < 4) && (i + j * 4 < length); j++) {
  45. sprintf(buf, " %08x", intptr[i / 4 + j]);
  46. strcat(line, buf);
  47. }
  48. buf[0] = ' ';
  49. buf[2] = 0;
  50. for (j = 0; (j < 16) && (i + j < length); j++) {
  51. buf[1] = isprint(charptr[i + j]) ? charptr[i + j] : '.';
  52. strcat(line, buf);
  53. }
  54. printk(KERN_DEBUG "%s\n", line);
  55. }
  56. }
  57. #ifdef CONFIG_CIFS_DEBUG2
  58. void cifs_dump_detail(struct smb_hdr *smb)
  59. {
  60. cERROR(1, ("Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d",
  61. smb->Command, smb->Status.CifsError,
  62. smb->Flags, smb->Flags2, smb->Mid, smb->Pid));
  63. cERROR(1, ("smb buf %p len %d", smb, smbCalcSize_LE(smb)));
  64. }
  65. void cifs_dump_mids(struct TCP_Server_Info *server)
  66. {
  67. struct list_head *tmp;
  68. struct mid_q_entry *mid_entry;
  69. if (server == NULL)
  70. return;
  71. cERROR(1, ("Dump pending requests:"));
  72. spin_lock(&GlobalMid_Lock);
  73. list_for_each(tmp, &server->pending_mid_q) {
  74. mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
  75. if (mid_entry) {
  76. cERROR(1, ("State: %d Cmd: %d Pid: %d Tsk: %p Mid %d",
  77. mid_entry->midState,
  78. (int)mid_entry->command,
  79. mid_entry->pid,
  80. mid_entry->tsk,
  81. mid_entry->mid));
  82. #ifdef CONFIG_CIFS_STATS2
  83. cERROR(1, ("IsLarge: %d buf: %p time rcv: %ld now: %ld",
  84. mid_entry->largeBuf,
  85. mid_entry->resp_buf,
  86. mid_entry->when_received,
  87. jiffies));
  88. #endif /* STATS2 */
  89. cERROR(1, ("IsMult: %d IsEnd: %d", mid_entry->multiRsp,
  90. mid_entry->multiEnd));
  91. if (mid_entry->resp_buf) {
  92. cifs_dump_detail(mid_entry->resp_buf);
  93. cifs_dump_mem("existing buf: ",
  94. mid_entry->resp_buf,
  95. 62 /* fixme */);
  96. }
  97. }
  98. }
  99. spin_unlock(&GlobalMid_Lock);
  100. }
  101. #endif /* CONFIG_CIFS_DEBUG2 */
  102. #ifdef CONFIG_PROC_FS
  103. static int
  104. cifs_debug_data_read(char *buf, char **beginBuffer, off_t offset,
  105. int count, int *eof, void *data)
  106. {
  107. struct list_head *tmp;
  108. struct list_head *tmp1;
  109. struct mid_q_entry *mid_entry;
  110. struct cifsSesInfo *ses;
  111. struct cifsTconInfo *tcon;
  112. int i;
  113. int length = 0;
  114. char *original_buf = buf;
  115. *beginBuffer = buf + offset;
  116. length =
  117. sprintf(buf,
  118. "Display Internal CIFS Data Structures for Debugging\n"
  119. "---------------------------------------------------\n");
  120. buf += length;
  121. length = sprintf(buf, "CIFS Version %s\n", CIFS_VERSION);
  122. buf += length;
  123. length = sprintf(buf,
  124. "Active VFS Requests: %d\n", GlobalTotalActiveXid);
  125. buf += length;
  126. length = sprintf(buf, "Servers:");
  127. buf += length;
  128. i = 0;
  129. read_lock(&GlobalSMBSeslock);
  130. list_for_each(tmp, &GlobalSMBSessionList) {
  131. i++;
  132. ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
  133. if ((ses->serverDomain == NULL) || (ses->serverOS == NULL) ||
  134. (ses->serverNOS == NULL)) {
  135. buf += sprintf(buf, "\nentry for %s not fully "
  136. "displayed\n\t", ses->serverName);
  137. } else {
  138. length =
  139. sprintf(buf,
  140. "\n%d) Name: %s Domain: %s Mounts: %d OS:"
  141. " %s \n\tNOS: %s\tCapability: 0x%x\n\tSMB"
  142. " session status: %d\t",
  143. i, ses->serverName, ses->serverDomain,
  144. atomic_read(&ses->inUse),
  145. ses->serverOS, ses->serverNOS,
  146. ses->capabilities, ses->status);
  147. buf += length;
  148. }
  149. if (ses->server) {
  150. buf += sprintf(buf, "TCP status: %d\n\tLocal Users To "
  151. "Server: %d SecMode: 0x%x Req On Wire: %d",
  152. ses->server->tcpStatus,
  153. atomic_read(&ses->server->socketUseCount),
  154. ses->server->secMode,
  155. atomic_read(&ses->server->inFlight));
  156. #ifdef CONFIG_CIFS_STATS2
  157. buf += sprintf(buf, " In Send: %d In MaxReq Wait: %d",
  158. atomic_read(&ses->server->inSend),
  159. atomic_read(&ses->server->num_waiters));
  160. #endif
  161. length = sprintf(buf, "\nMIDs:\n");
  162. buf += length;
  163. spin_lock(&GlobalMid_Lock);
  164. list_for_each(tmp1, &ses->server->pending_mid_q) {
  165. mid_entry = list_entry(tmp1, struct
  166. mid_q_entry,
  167. qhead);
  168. if (mid_entry) {
  169. length = sprintf(buf,
  170. "State: %d com: %d pid:"
  171. " %d tsk: %p mid %d\n",
  172. mid_entry->midState,
  173. (int)mid_entry->command,
  174. mid_entry->pid,
  175. mid_entry->tsk,
  176. mid_entry->mid);
  177. buf += length;
  178. }
  179. }
  180. spin_unlock(&GlobalMid_Lock);
  181. }
  182. }
  183. read_unlock(&GlobalSMBSeslock);
  184. sprintf(buf, "\n");
  185. buf++;
  186. length = sprintf(buf, "Shares:");
  187. buf += length;
  188. i = 0;
  189. read_lock(&GlobalSMBSeslock);
  190. list_for_each(tmp, &GlobalTreeConnectionList) {
  191. __u32 dev_type;
  192. i++;
  193. tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
  194. dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
  195. length =
  196. sprintf(buf,
  197. "\n%d) %s Uses: %d Type: %s DevInfo: 0x%x "
  198. "Attributes: 0x%x\nPathComponentMax: %d Status: %d",
  199. i, tcon->treeName,
  200. atomic_read(&tcon->useCount),
  201. tcon->nativeFileSystem,
  202. le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
  203. le32_to_cpu(tcon->fsAttrInfo.Attributes),
  204. le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
  205. tcon->tidStatus);
  206. buf += length;
  207. if (dev_type == FILE_DEVICE_DISK)
  208. length = sprintf(buf, " type: DISK ");
  209. else if (dev_type == FILE_DEVICE_CD_ROM)
  210. length = sprintf(buf, " type: CDROM ");
  211. else
  212. length =
  213. sprintf(buf, " type: %d ", dev_type);
  214. buf += length;
  215. if (tcon->tidStatus == CifsNeedReconnect) {
  216. buf += sprintf(buf, "\tDISCONNECTED ");
  217. length += 14;
  218. }
  219. }
  220. read_unlock(&GlobalSMBSeslock);
  221. length = sprintf(buf, "\n");
  222. buf += length;
  223. /* BB add code to dump additional info such as TCP session info now */
  224. /* Now calculate total size of returned data */
  225. length = buf - original_buf;
  226. if (offset + count >= length)
  227. *eof = 1;
  228. if (length < offset) {
  229. *eof = 1;
  230. return 0;
  231. } else {
  232. length = length - offset;
  233. }
  234. if (length > count)
  235. length = count;
  236. return length;
  237. }
  238. #ifdef CONFIG_CIFS_STATS
  239. static int
  240. cifs_stats_write(struct file *file, const char __user *buffer,
  241. unsigned long count, void *data)
  242. {
  243. char c;
  244. int rc;
  245. struct list_head *tmp;
  246. struct cifsTconInfo *tcon;
  247. rc = get_user(c, buffer);
  248. if (rc)
  249. return rc;
  250. if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
  251. read_lock(&GlobalSMBSeslock);
  252. #ifdef CONFIG_CIFS_STATS2
  253. atomic_set(&totBufAllocCount, 0);
  254. atomic_set(&totSmBufAllocCount, 0);
  255. #endif /* CONFIG_CIFS_STATS2 */
  256. list_for_each(tmp, &GlobalTreeConnectionList) {
  257. tcon = list_entry(tmp, struct cifsTconInfo,
  258. cifsConnectionList);
  259. atomic_set(&tcon->num_smbs_sent, 0);
  260. atomic_set(&tcon->num_writes, 0);
  261. atomic_set(&tcon->num_reads, 0);
  262. atomic_set(&tcon->num_oplock_brks, 0);
  263. atomic_set(&tcon->num_opens, 0);
  264. atomic_set(&tcon->num_closes, 0);
  265. atomic_set(&tcon->num_deletes, 0);
  266. atomic_set(&tcon->num_mkdirs, 0);
  267. atomic_set(&tcon->num_rmdirs, 0);
  268. atomic_set(&tcon->num_renames, 0);
  269. atomic_set(&tcon->num_t2renames, 0);
  270. atomic_set(&tcon->num_ffirst, 0);
  271. atomic_set(&tcon->num_fnext, 0);
  272. atomic_set(&tcon->num_fclose, 0);
  273. atomic_set(&tcon->num_hardlinks, 0);
  274. atomic_set(&tcon->num_symlinks, 0);
  275. atomic_set(&tcon->num_locks, 0);
  276. }
  277. read_unlock(&GlobalSMBSeslock);
  278. }
  279. return count;
  280. }
  281. static int
  282. cifs_stats_read(char *buf, char **beginBuffer, off_t offset,
  283. int count, int *eof, void *data)
  284. {
  285. int item_length, i, length;
  286. struct list_head *tmp;
  287. struct cifsTconInfo *tcon;
  288. *beginBuffer = buf + offset;
  289. length = sprintf(buf,
  290. "Resources in use\nCIFS Session: %d\n",
  291. sesInfoAllocCount.counter);
  292. buf += length;
  293. item_length =
  294. sprintf(buf, "Share (unique mount targets): %d\n",
  295. tconInfoAllocCount.counter);
  296. length += item_length;
  297. buf += item_length;
  298. item_length =
  299. sprintf(buf, "SMB Request/Response Buffer: %d Pool size: %d\n",
  300. bufAllocCount.counter,
  301. cifs_min_rcv + tcpSesAllocCount.counter);
  302. length += item_length;
  303. buf += item_length;
  304. item_length =
  305. sprintf(buf, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
  306. smBufAllocCount.counter, cifs_min_small);
  307. length += item_length;
  308. buf += item_length;
  309. #ifdef CONFIG_CIFS_STATS2
  310. item_length = sprintf(buf, "Total Large %d Small %d Allocations\n",
  311. atomic_read(&totBufAllocCount),
  312. atomic_read(&totSmBufAllocCount));
  313. length += item_length;
  314. buf += item_length;
  315. #endif /* CONFIG_CIFS_STATS2 */
  316. item_length =
  317. sprintf(buf, "Operations (MIDs): %d\n",
  318. midCount.counter);
  319. length += item_length;
  320. buf += item_length;
  321. item_length = sprintf(buf,
  322. "\n%d session %d share reconnects\n",
  323. tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
  324. length += item_length;
  325. buf += item_length;
  326. item_length = sprintf(buf,
  327. "Total vfs operations: %d maximum at one time: %d\n",
  328. GlobalCurrentXid, GlobalMaxActiveXid);
  329. length += item_length;
  330. buf += item_length;
  331. i = 0;
  332. read_lock(&GlobalSMBSeslock);
  333. list_for_each(tmp, &GlobalTreeConnectionList) {
  334. i++;
  335. tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
  336. item_length = sprintf(buf, "\n%d) %s", i, tcon->treeName);
  337. buf += item_length;
  338. length += item_length;
  339. if (tcon->tidStatus == CifsNeedReconnect) {
  340. buf += sprintf(buf, "\tDISCONNECTED ");
  341. length += 14;
  342. }
  343. item_length = sprintf(buf, "\nSMBs: %d Oplock Breaks: %d",
  344. atomic_read(&tcon->num_smbs_sent),
  345. atomic_read(&tcon->num_oplock_brks));
  346. buf += item_length;
  347. length += item_length;
  348. item_length = sprintf(buf, "\nReads: %d Bytes: %lld",
  349. atomic_read(&tcon->num_reads),
  350. (long long)(tcon->bytes_read));
  351. buf += item_length;
  352. length += item_length;
  353. item_length = sprintf(buf, "\nWrites: %d Bytes: %lld",
  354. atomic_read(&tcon->num_writes),
  355. (long long)(tcon->bytes_written));
  356. buf += item_length;
  357. length += item_length;
  358. item_length = sprintf(buf,
  359. "\nLocks: %d HardLinks: %d Symlinks: %d",
  360. atomic_read(&tcon->num_locks),
  361. atomic_read(&tcon->num_hardlinks),
  362. atomic_read(&tcon->num_symlinks));
  363. buf += item_length;
  364. length += item_length;
  365. item_length = sprintf(buf, "\nOpens: %d Closes: %d Deletes: %d",
  366. atomic_read(&tcon->num_opens),
  367. atomic_read(&tcon->num_closes),
  368. atomic_read(&tcon->num_deletes));
  369. buf += item_length;
  370. length += item_length;
  371. item_length = sprintf(buf, "\nMkdirs: %d Rmdirs: %d",
  372. atomic_read(&tcon->num_mkdirs),
  373. atomic_read(&tcon->num_rmdirs));
  374. buf += item_length;
  375. length += item_length;
  376. item_length = sprintf(buf, "\nRenames: %d T2 Renames %d",
  377. atomic_read(&tcon->num_renames),
  378. atomic_read(&tcon->num_t2renames));
  379. buf += item_length;
  380. length += item_length;
  381. item_length = sprintf(buf, "\nFindFirst: %d FNext %d FClose %d",
  382. atomic_read(&tcon->num_ffirst),
  383. atomic_read(&tcon->num_fnext),
  384. atomic_read(&tcon->num_fclose));
  385. buf += item_length;
  386. length += item_length;
  387. }
  388. read_unlock(&GlobalSMBSeslock);
  389. buf += sprintf(buf, "\n");
  390. length++;
  391. if (offset + count >= length)
  392. *eof = 1;
  393. if (length < offset) {
  394. *eof = 1;
  395. return 0;
  396. } else {
  397. length = length - offset;
  398. }
  399. if (length > count)
  400. length = count;
  401. return length;
  402. }
  403. #endif
  404. static struct proc_dir_entry *proc_fs_cifs;
  405. read_proc_t cifs_txanchor_read;
  406. static read_proc_t cifsFYI_read;
  407. static write_proc_t cifsFYI_write;
  408. static read_proc_t oplockEnabled_read;
  409. static write_proc_t oplockEnabled_write;
  410. static read_proc_t lookupFlag_read;
  411. static write_proc_t lookupFlag_write;
  412. static read_proc_t traceSMB_read;
  413. static write_proc_t traceSMB_write;
  414. static read_proc_t multiuser_mount_read;
  415. static write_proc_t multiuser_mount_write;
  416. static read_proc_t security_flags_read;
  417. static write_proc_t security_flags_write;
  418. /* static read_proc_t ntlmv2_enabled_read;
  419. static write_proc_t ntlmv2_enabled_write;
  420. static read_proc_t packet_signing_enabled_read;
  421. static write_proc_t packet_signing_enabled_write;*/
  422. static read_proc_t experimEnabled_read;
  423. static write_proc_t experimEnabled_write;
  424. static read_proc_t linuxExtensionsEnabled_read;
  425. static write_proc_t linuxExtensionsEnabled_write;
  426. void
  427. cifs_proc_init(void)
  428. {
  429. struct proc_dir_entry *pde;
  430. proc_fs_cifs = proc_mkdir("cifs", proc_root_fs);
  431. if (proc_fs_cifs == NULL)
  432. return;
  433. proc_fs_cifs->owner = THIS_MODULE;
  434. create_proc_read_entry("DebugData", 0, proc_fs_cifs,
  435. cifs_debug_data_read, NULL);
  436. #ifdef CONFIG_CIFS_STATS
  437. pde = create_proc_read_entry("Stats", 0, proc_fs_cifs,
  438. cifs_stats_read, NULL);
  439. if (pde)
  440. pde->write_proc = cifs_stats_write;
  441. #endif
  442. pde = create_proc_read_entry("cifsFYI", 0, proc_fs_cifs,
  443. cifsFYI_read, NULL);
  444. if (pde)
  445. pde->write_proc = cifsFYI_write;
  446. pde =
  447. create_proc_read_entry("traceSMB", 0, proc_fs_cifs,
  448. traceSMB_read, NULL);
  449. if (pde)
  450. pde->write_proc = traceSMB_write;
  451. pde = create_proc_read_entry("OplockEnabled", 0, proc_fs_cifs,
  452. oplockEnabled_read, NULL);
  453. if (pde)
  454. pde->write_proc = oplockEnabled_write;
  455. pde = create_proc_read_entry("Experimental", 0, proc_fs_cifs,
  456. experimEnabled_read, NULL);
  457. if (pde)
  458. pde->write_proc = experimEnabled_write;
  459. pde = create_proc_read_entry("LinuxExtensionsEnabled", 0, proc_fs_cifs,
  460. linuxExtensionsEnabled_read, NULL);
  461. if (pde)
  462. pde->write_proc = linuxExtensionsEnabled_write;
  463. pde =
  464. create_proc_read_entry("MultiuserMount", 0, proc_fs_cifs,
  465. multiuser_mount_read, NULL);
  466. if (pde)
  467. pde->write_proc = multiuser_mount_write;
  468. pde =
  469. create_proc_read_entry("SecurityFlags", 0, proc_fs_cifs,
  470. security_flags_read, NULL);
  471. if (pde)
  472. pde->write_proc = security_flags_write;
  473. pde =
  474. create_proc_read_entry("LookupCacheEnabled", 0, proc_fs_cifs,
  475. lookupFlag_read, NULL);
  476. if (pde)
  477. pde->write_proc = lookupFlag_write;
  478. /* pde =
  479. create_proc_read_entry("NTLMV2Enabled", 0, proc_fs_cifs,
  480. ntlmv2_enabled_read, NULL);
  481. if (pde)
  482. pde->write_proc = ntlmv2_enabled_write;
  483. pde =
  484. create_proc_read_entry("PacketSigningEnabled", 0, proc_fs_cifs,
  485. packet_signing_enabled_read, NULL);
  486. if (pde)
  487. pde->write_proc = packet_signing_enabled_write;*/
  488. }
  489. void
  490. cifs_proc_clean(void)
  491. {
  492. if (proc_fs_cifs == NULL)
  493. return;
  494. remove_proc_entry("DebugData", proc_fs_cifs);
  495. remove_proc_entry("cifsFYI", proc_fs_cifs);
  496. remove_proc_entry("traceSMB", proc_fs_cifs);
  497. #ifdef CONFIG_CIFS_STATS
  498. remove_proc_entry("Stats", proc_fs_cifs);
  499. #endif
  500. remove_proc_entry("MultiuserMount", proc_fs_cifs);
  501. remove_proc_entry("OplockEnabled", proc_fs_cifs);
  502. /* remove_proc_entry("NTLMV2Enabled",proc_fs_cifs); */
  503. remove_proc_entry("SecurityFlags", proc_fs_cifs);
  504. /* remove_proc_entry("PacketSigningEnabled", proc_fs_cifs); */
  505. remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
  506. remove_proc_entry("Experimental", proc_fs_cifs);
  507. remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
  508. remove_proc_entry("cifs", proc_root_fs);
  509. }
  510. static int
  511. cifsFYI_read(char *page, char **start, off_t off, int count,
  512. int *eof, void *data)
  513. {
  514. int len;
  515. len = sprintf(page, "%d\n", cifsFYI);
  516. len -= off;
  517. *start = page + off;
  518. if (len > count)
  519. len = count;
  520. else
  521. *eof = 1;
  522. if (len < 0)
  523. len = 0;
  524. return len;
  525. }
  526. static int
  527. cifsFYI_write(struct file *file, const char __user *buffer,
  528. unsigned long count, void *data)
  529. {
  530. char c;
  531. int rc;
  532. rc = get_user(c, buffer);
  533. if (rc)
  534. return rc;
  535. if (c == '0' || c == 'n' || c == 'N')
  536. cifsFYI = 0;
  537. else if (c == '1' || c == 'y' || c == 'Y')
  538. cifsFYI = 1;
  539. else if ((c > '1') && (c <= '9'))
  540. cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
  541. return count;
  542. }
  543. static int
  544. oplockEnabled_read(char *page, char **start, off_t off,
  545. int count, int *eof, void *data)
  546. {
  547. int len;
  548. len = sprintf(page, "%d\n", oplockEnabled);
  549. len -= off;
  550. *start = page + off;
  551. if (len > count)
  552. len = count;
  553. else
  554. *eof = 1;
  555. if (len < 0)
  556. len = 0;
  557. return len;
  558. }
  559. static int
  560. oplockEnabled_write(struct file *file, const char __user *buffer,
  561. unsigned long count, void *data)
  562. {
  563. char c;
  564. int rc;
  565. rc = get_user(c, buffer);
  566. if (rc)
  567. return rc;
  568. if (c == '0' || c == 'n' || c == 'N')
  569. oplockEnabled = 0;
  570. else if (c == '1' || c == 'y' || c == 'Y')
  571. oplockEnabled = 1;
  572. return count;
  573. }
  574. static int
  575. experimEnabled_read(char *page, char **start, off_t off,
  576. int count, int *eof, void *data)
  577. {
  578. int len;
  579. len = sprintf(page, "%d\n", experimEnabled);
  580. len -= off;
  581. *start = page + off;
  582. if (len > count)
  583. len = count;
  584. else
  585. *eof = 1;
  586. if (len < 0)
  587. len = 0;
  588. return len;
  589. }
  590. static int
  591. experimEnabled_write(struct file *file, const char __user *buffer,
  592. unsigned long count, void *data)
  593. {
  594. char c;
  595. int rc;
  596. rc = get_user(c, buffer);
  597. if (rc)
  598. return rc;
  599. if (c == '0' || c == 'n' || c == 'N')
  600. experimEnabled = 0;
  601. else if (c == '1' || c == 'y' || c == 'Y')
  602. experimEnabled = 1;
  603. else if (c == '2')
  604. experimEnabled = 2;
  605. return count;
  606. }
  607. static int
  608. linuxExtensionsEnabled_read(char *page, char **start, off_t off,
  609. int count, int *eof, void *data)
  610. {
  611. int len;
  612. len = sprintf(page, "%d\n", linuxExtEnabled);
  613. len -= off;
  614. *start = page + off;
  615. if (len > count)
  616. len = count;
  617. else
  618. *eof = 1;
  619. if (len < 0)
  620. len = 0;
  621. return len;
  622. }
  623. static int
  624. linuxExtensionsEnabled_write(struct file *file, const char __user *buffer,
  625. unsigned long count, void *data)
  626. {
  627. char c;
  628. int rc;
  629. rc = get_user(c, buffer);
  630. if (rc)
  631. return rc;
  632. if (c == '0' || c == 'n' || c == 'N')
  633. linuxExtEnabled = 0;
  634. else if (c == '1' || c == 'y' || c == 'Y')
  635. linuxExtEnabled = 1;
  636. return count;
  637. }
  638. static int
  639. lookupFlag_read(char *page, char **start, off_t off,
  640. int count, int *eof, void *data)
  641. {
  642. int len;
  643. len = sprintf(page, "%d\n", lookupCacheEnabled);
  644. len -= off;
  645. *start = page + off;
  646. if (len > count)
  647. len = count;
  648. else
  649. *eof = 1;
  650. if (len < 0)
  651. len = 0;
  652. return len;
  653. }
  654. static int
  655. lookupFlag_write(struct file *file, const char __user *buffer,
  656. unsigned long count, void *data)
  657. {
  658. char c;
  659. int rc;
  660. rc = get_user(c, buffer);
  661. if (rc)
  662. return rc;
  663. if (c == '0' || c == 'n' || c == 'N')
  664. lookupCacheEnabled = 0;
  665. else if (c == '1' || c == 'y' || c == 'Y')
  666. lookupCacheEnabled = 1;
  667. return count;
  668. }
  669. static int
  670. traceSMB_read(char *page, char **start, off_t off, int count,
  671. int *eof, void *data)
  672. {
  673. int len;
  674. len = sprintf(page, "%d\n", traceSMB);
  675. len -= off;
  676. *start = page + off;
  677. if (len > count)
  678. len = count;
  679. else
  680. *eof = 1;
  681. if (len < 0)
  682. len = 0;
  683. return len;
  684. }
  685. static int
  686. traceSMB_write(struct file *file, const char __user *buffer,
  687. unsigned long count, void *data)
  688. {
  689. char c;
  690. int rc;
  691. rc = get_user(c, buffer);
  692. if (rc)
  693. return rc;
  694. if (c == '0' || c == 'n' || c == 'N')
  695. traceSMB = 0;
  696. else if (c == '1' || c == 'y' || c == 'Y')
  697. traceSMB = 1;
  698. return count;
  699. }
  700. static int
  701. multiuser_mount_read(char *page, char **start, off_t off,
  702. int count, int *eof, void *data)
  703. {
  704. int len;
  705. len = sprintf(page, "%d\n", multiuser_mount);
  706. len -= off;
  707. *start = page + off;
  708. if (len > count)
  709. len = count;
  710. else
  711. *eof = 1;
  712. if (len < 0)
  713. len = 0;
  714. return len;
  715. }
  716. static int
  717. multiuser_mount_write(struct file *file, const char __user *buffer,
  718. unsigned long count, void *data)
  719. {
  720. char c;
  721. int rc;
  722. rc = get_user(c, buffer);
  723. if (rc)
  724. return rc;
  725. if (c == '0' || c == 'n' || c == 'N')
  726. multiuser_mount = 0;
  727. else if (c == '1' || c == 'y' || c == 'Y')
  728. multiuser_mount = 1;
  729. return count;
  730. }
  731. static int
  732. security_flags_read(char *page, char **start, off_t off,
  733. int count, int *eof, void *data)
  734. {
  735. int len;
  736. len = sprintf(page, "0x%x\n", extended_security);
  737. len -= off;
  738. *start = page + off;
  739. if (len > count)
  740. len = count;
  741. else
  742. *eof = 1;
  743. if (len < 0)
  744. len = 0;
  745. return len;
  746. }
  747. static int
  748. security_flags_write(struct file *file, const char __user *buffer,
  749. unsigned long count, void *data)
  750. {
  751. unsigned int flags;
  752. char flags_string[12];
  753. char c;
  754. if ((count < 1) || (count > 11))
  755. return -EINVAL;
  756. memset(flags_string, 0, 12);
  757. if (copy_from_user(flags_string, buffer, count))
  758. return -EFAULT;
  759. if (count < 3) {
  760. /* single char or single char followed by null */
  761. c = flags_string[0];
  762. if (c == '0' || c == 'n' || c == 'N')
  763. extended_security = CIFSSEC_DEF; /* default */
  764. else if (c == '1' || c == 'y' || c == 'Y')
  765. extended_security = CIFSSEC_MAX;
  766. return count;
  767. }
  768. /* else we have a number */
  769. flags = simple_strtoul(flags_string, NULL, 0);
  770. cFYI(1, ("sec flags 0x%x", flags));
  771. if (flags <= 0) {
  772. cERROR(1, ("invalid security flags %s", flags_string));
  773. return -EINVAL;
  774. }
  775. if (flags & ~CIFSSEC_MASK) {
  776. cERROR(1, ("attempt to set unsupported security flags 0x%x",
  777. flags & ~CIFSSEC_MASK));
  778. return -EINVAL;
  779. }
  780. /* flags look ok - update the global security flags for cifs module */
  781. extended_security = flags;
  782. if (extended_security & CIFSSEC_MUST_SIGN) {
  783. /* requiring signing implies signing is allowed */
  784. extended_security |= CIFSSEC_MAY_SIGN;
  785. cFYI(1, ("packet signing now required"));
  786. } else if ((extended_security & CIFSSEC_MAY_SIGN) == 0) {
  787. cFYI(1, ("packet signing disabled"));
  788. }
  789. /* BB should we turn on MAY flags for other MUST options? */
  790. return count;
  791. }
  792. #endif