cifs_debug.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795
  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. cERROR(1, ("State: %d Cmd: %d Pid: %d Tsk: %p Mid %d",
  76. mid_entry->midState,
  77. (int)mid_entry->command,
  78. mid_entry->pid,
  79. mid_entry->tsk,
  80. mid_entry->mid));
  81. #ifdef CONFIG_CIFS_STATS2
  82. cERROR(1, ("IsLarge: %d buf: %p time rcv: %ld now: %ld",
  83. mid_entry->largeBuf,
  84. mid_entry->resp_buf,
  85. mid_entry->when_received,
  86. jiffies));
  87. #endif /* STATS2 */
  88. cERROR(1, ("IsMult: %d IsEnd: %d", mid_entry->multiRsp,
  89. mid_entry->multiEnd));
  90. if (mid_entry->resp_buf) {
  91. cifs_dump_detail(mid_entry->resp_buf);
  92. cifs_dump_mem("existing buf: ",
  93. mid_entry->resp_buf, 62);
  94. }
  95. }
  96. spin_unlock(&GlobalMid_Lock);
  97. }
  98. #endif /* CONFIG_CIFS_DEBUG2 */
  99. #ifdef CONFIG_PROC_FS
  100. static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
  101. {
  102. struct list_head *tmp1, *tmp2, *tmp3;
  103. struct mid_q_entry *mid_entry;
  104. struct TCP_Server_Info *server;
  105. struct cifsSesInfo *ses;
  106. struct cifsTconInfo *tcon;
  107. int i, j;
  108. __u32 dev_type;
  109. seq_puts(m,
  110. "Display Internal CIFS Data Structures for Debugging\n"
  111. "---------------------------------------------------\n");
  112. seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
  113. seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
  114. seq_printf(m, "Servers:");
  115. i = 0;
  116. read_lock(&cifs_tcp_ses_lock);
  117. list_for_each(tmp1, &cifs_tcp_ses_list) {
  118. server = list_entry(tmp1, struct TCP_Server_Info,
  119. tcp_ses_list);
  120. i++;
  121. list_for_each(tmp2, &server->smb_ses_list) {
  122. ses = list_entry(tmp2, struct cifsSesInfo,
  123. smb_ses_list);
  124. if ((ses->serverDomain == NULL) ||
  125. (ses->serverOS == NULL) ||
  126. (ses->serverNOS == NULL)) {
  127. seq_printf(m, "\n%d) entry for %s not fully "
  128. "displayed\n\t", i, ses->serverName);
  129. } else {
  130. seq_printf(m,
  131. "\n%d) Name: %s Domain: %s Uses: %d OS:"
  132. " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
  133. " session status: %d\t",
  134. i, ses->serverName, ses->serverDomain,
  135. ses->ses_count, ses->serverOS, ses->serverNOS,
  136. ses->capabilities, ses->status);
  137. }
  138. seq_printf(m, "TCP status: %d\n\tLocal Users To "
  139. "Server: %d SecMode: 0x%x Req On Wire: %d",
  140. server->tcpStatus, server->srv_count,
  141. server->secMode,
  142. atomic_read(&server->inFlight));
  143. #ifdef CONFIG_CIFS_STATS2
  144. seq_printf(m, " In Send: %d In MaxReq Wait: %d",
  145. atomic_read(&server->inSend),
  146. atomic_read(&server->num_waiters));
  147. #endif
  148. seq_puts(m, "\n\tShares:");
  149. j = 0;
  150. list_for_each(tmp3, &ses->tcon_list) {
  151. tcon = list_entry(tmp3, struct cifsTconInfo,
  152. tcon_list);
  153. ++j;
  154. dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
  155. seq_printf(m, "\n\t%d) %s Mounts: %d ", j,
  156. tcon->treeName, tcon->tc_count);
  157. if (tcon->nativeFileSystem) {
  158. seq_printf(m, "Type: %s ",
  159. tcon->nativeFileSystem);
  160. }
  161. seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x"
  162. "\nPathComponentMax: %d Status: 0x%d",
  163. le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
  164. le32_to_cpu(tcon->fsAttrInfo.Attributes),
  165. le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
  166. tcon->tidStatus);
  167. if (dev_type == FILE_DEVICE_DISK)
  168. seq_puts(m, " type: DISK ");
  169. else if (dev_type == FILE_DEVICE_CD_ROM)
  170. seq_puts(m, " type: CDROM ");
  171. else
  172. seq_printf(m, " type: %d ", dev_type);
  173. if (tcon->need_reconnect)
  174. seq_puts(m, "\tDISCONNECTED ");
  175. seq_putc(m, '\n');
  176. }
  177. seq_puts(m, "\n\tMIDs:\n");
  178. spin_lock(&GlobalMid_Lock);
  179. list_for_each(tmp3, &server->pending_mid_q) {
  180. mid_entry = list_entry(tmp3, struct mid_q_entry,
  181. qhead);
  182. seq_printf(m, "\tState: %d com: %d pid:"
  183. " %d tsk: %p mid %d\n",
  184. mid_entry->midState,
  185. (int)mid_entry->command,
  186. mid_entry->pid,
  187. mid_entry->tsk,
  188. mid_entry->mid);
  189. }
  190. spin_unlock(&GlobalMid_Lock);
  191. }
  192. }
  193. read_unlock(&cifs_tcp_ses_lock);
  194. seq_putc(m, '\n');
  195. /* BB add code to dump additional info such as TCP session info now */
  196. return 0;
  197. }
  198. static int cifs_debug_data_proc_open(struct inode *inode, struct file *file)
  199. {
  200. return single_open(file, cifs_debug_data_proc_show, NULL);
  201. }
  202. static const struct file_operations cifs_debug_data_proc_fops = {
  203. .owner = THIS_MODULE,
  204. .open = cifs_debug_data_proc_open,
  205. .read = seq_read,
  206. .llseek = seq_lseek,
  207. .release = single_release,
  208. };
  209. #ifdef CONFIG_CIFS_STATS
  210. static ssize_t cifs_stats_proc_write(struct file *file,
  211. const char __user *buffer, size_t count, loff_t *ppos)
  212. {
  213. char c;
  214. int rc;
  215. struct list_head *tmp1, *tmp2, *tmp3;
  216. struct TCP_Server_Info *server;
  217. struct cifsSesInfo *ses;
  218. struct cifsTconInfo *tcon;
  219. rc = get_user(c, buffer);
  220. if (rc)
  221. return rc;
  222. if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
  223. #ifdef CONFIG_CIFS_STATS2
  224. atomic_set(&totBufAllocCount, 0);
  225. atomic_set(&totSmBufAllocCount, 0);
  226. #endif /* CONFIG_CIFS_STATS2 */
  227. read_lock(&cifs_tcp_ses_lock);
  228. list_for_each(tmp1, &cifs_tcp_ses_list) {
  229. server = list_entry(tmp1, struct TCP_Server_Info,
  230. tcp_ses_list);
  231. list_for_each(tmp2, &server->smb_ses_list) {
  232. ses = list_entry(tmp2, struct cifsSesInfo,
  233. smb_ses_list);
  234. list_for_each(tmp3, &ses->tcon_list) {
  235. tcon = list_entry(tmp3,
  236. struct cifsTconInfo,
  237. tcon_list);
  238. atomic_set(&tcon->num_smbs_sent, 0);
  239. atomic_set(&tcon->num_writes, 0);
  240. atomic_set(&tcon->num_reads, 0);
  241. atomic_set(&tcon->num_oplock_brks, 0);
  242. atomic_set(&tcon->num_opens, 0);
  243. atomic_set(&tcon->num_closes, 0);
  244. atomic_set(&tcon->num_deletes, 0);
  245. atomic_set(&tcon->num_mkdirs, 0);
  246. atomic_set(&tcon->num_rmdirs, 0);
  247. atomic_set(&tcon->num_renames, 0);
  248. atomic_set(&tcon->num_t2renames, 0);
  249. atomic_set(&tcon->num_ffirst, 0);
  250. atomic_set(&tcon->num_fnext, 0);
  251. atomic_set(&tcon->num_fclose, 0);
  252. atomic_set(&tcon->num_hardlinks, 0);
  253. atomic_set(&tcon->num_symlinks, 0);
  254. atomic_set(&tcon->num_locks, 0);
  255. }
  256. }
  257. }
  258. read_unlock(&cifs_tcp_ses_lock);
  259. }
  260. return count;
  261. }
  262. static int cifs_stats_proc_show(struct seq_file *m, void *v)
  263. {
  264. int i;
  265. struct list_head *tmp1, *tmp2, *tmp3;
  266. struct TCP_Server_Info *server;
  267. struct cifsSesInfo *ses;
  268. struct cifsTconInfo *tcon;
  269. seq_printf(m,
  270. "Resources in use\nCIFS Session: %d\n",
  271. sesInfoAllocCount.counter);
  272. seq_printf(m, "Share (unique mount targets): %d\n",
  273. tconInfoAllocCount.counter);
  274. seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
  275. bufAllocCount.counter,
  276. cifs_min_rcv + tcpSesAllocCount.counter);
  277. seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
  278. smBufAllocCount.counter, cifs_min_small);
  279. #ifdef CONFIG_CIFS_STATS2
  280. seq_printf(m, "Total Large %d Small %d Allocations\n",
  281. atomic_read(&totBufAllocCount),
  282. atomic_read(&totSmBufAllocCount));
  283. #endif /* CONFIG_CIFS_STATS2 */
  284. seq_printf(m, "Operations (MIDs): %d\n", midCount.counter);
  285. seq_printf(m,
  286. "\n%d session %d share reconnects\n",
  287. tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
  288. seq_printf(m,
  289. "Total vfs operations: %d maximum at one time: %d\n",
  290. GlobalCurrentXid, GlobalMaxActiveXid);
  291. i = 0;
  292. read_lock(&cifs_tcp_ses_lock);
  293. list_for_each(tmp1, &cifs_tcp_ses_list) {
  294. server = list_entry(tmp1, struct TCP_Server_Info,
  295. tcp_ses_list);
  296. list_for_each(tmp2, &server->smb_ses_list) {
  297. ses = list_entry(tmp2, struct cifsSesInfo,
  298. smb_ses_list);
  299. list_for_each(tmp3, &ses->tcon_list) {
  300. tcon = list_entry(tmp3,
  301. struct cifsTconInfo,
  302. tcon_list);
  303. i++;
  304. seq_printf(m, "\n%d) %s", i, tcon->treeName);
  305. if (tcon->need_reconnect)
  306. seq_puts(m, "\tDISCONNECTED ");
  307. seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
  308. atomic_read(&tcon->num_smbs_sent),
  309. atomic_read(&tcon->num_oplock_brks));
  310. seq_printf(m, "\nReads: %d Bytes: %lld",
  311. atomic_read(&tcon->num_reads),
  312. (long long)(tcon->bytes_read));
  313. seq_printf(m, "\nWrites: %d Bytes: %lld",
  314. atomic_read(&tcon->num_writes),
  315. (long long)(tcon->bytes_written));
  316. seq_printf(m, "\nLocks: %d HardLinks: %d "
  317. "Symlinks: %d",
  318. atomic_read(&tcon->num_locks),
  319. atomic_read(&tcon->num_hardlinks),
  320. atomic_read(&tcon->num_symlinks));
  321. seq_printf(m, "\nOpens: %d Closes: %d"
  322. "Deletes: %d",
  323. atomic_read(&tcon->num_opens),
  324. atomic_read(&tcon->num_closes),
  325. atomic_read(&tcon->num_deletes));
  326. seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
  327. atomic_read(&tcon->num_mkdirs),
  328. atomic_read(&tcon->num_rmdirs));
  329. seq_printf(m, "\nRenames: %d T2 Renames %d",
  330. atomic_read(&tcon->num_renames),
  331. atomic_read(&tcon->num_t2renames));
  332. seq_printf(m, "\nFindFirst: %d FNext %d "
  333. "FClose %d",
  334. atomic_read(&tcon->num_ffirst),
  335. atomic_read(&tcon->num_fnext),
  336. atomic_read(&tcon->num_fclose));
  337. }
  338. }
  339. }
  340. read_unlock(&cifs_tcp_ses_lock);
  341. seq_putc(m, '\n');
  342. return 0;
  343. }
  344. static int cifs_stats_proc_open(struct inode *inode, struct file *file)
  345. {
  346. return single_open(file, cifs_stats_proc_show, NULL);
  347. }
  348. static const struct file_operations cifs_stats_proc_fops = {
  349. .owner = THIS_MODULE,
  350. .open = cifs_stats_proc_open,
  351. .read = seq_read,
  352. .llseek = seq_lseek,
  353. .release = single_release,
  354. .write = cifs_stats_proc_write,
  355. };
  356. #endif /* STATS */
  357. static struct proc_dir_entry *proc_fs_cifs;
  358. static const struct file_operations cifsFYI_proc_fops;
  359. static const struct file_operations cifs_oplock_proc_fops;
  360. static const struct file_operations cifs_lookup_cache_proc_fops;
  361. static const struct file_operations traceSMB_proc_fops;
  362. static const struct file_operations cifs_multiuser_mount_proc_fops;
  363. static const struct file_operations cifs_security_flags_proc_fops;
  364. static const struct file_operations cifs_experimental_proc_fops;
  365. static const struct file_operations cifs_linux_ext_proc_fops;
  366. void
  367. cifs_proc_init(void)
  368. {
  369. proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
  370. if (proc_fs_cifs == NULL)
  371. return;
  372. proc_fs_cifs->owner = THIS_MODULE;
  373. proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
  374. #ifdef CONFIG_CIFS_STATS
  375. proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
  376. #endif /* STATS */
  377. proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
  378. proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
  379. proc_create("OplockEnabled", 0, proc_fs_cifs, &cifs_oplock_proc_fops);
  380. proc_create("Experimental", 0, proc_fs_cifs,
  381. &cifs_experimental_proc_fops);
  382. proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
  383. &cifs_linux_ext_proc_fops);
  384. proc_create("MultiuserMount", 0, proc_fs_cifs,
  385. &cifs_multiuser_mount_proc_fops);
  386. proc_create("SecurityFlags", 0, proc_fs_cifs,
  387. &cifs_security_flags_proc_fops);
  388. proc_create("LookupCacheEnabled", 0, proc_fs_cifs,
  389. &cifs_lookup_cache_proc_fops);
  390. }
  391. void
  392. cifs_proc_clean(void)
  393. {
  394. if (proc_fs_cifs == NULL)
  395. return;
  396. remove_proc_entry("DebugData", proc_fs_cifs);
  397. remove_proc_entry("cifsFYI", proc_fs_cifs);
  398. remove_proc_entry("traceSMB", proc_fs_cifs);
  399. #ifdef CONFIG_CIFS_STATS
  400. remove_proc_entry("Stats", proc_fs_cifs);
  401. #endif
  402. remove_proc_entry("MultiuserMount", proc_fs_cifs);
  403. remove_proc_entry("OplockEnabled", proc_fs_cifs);
  404. remove_proc_entry("SecurityFlags", proc_fs_cifs);
  405. remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
  406. remove_proc_entry("Experimental", proc_fs_cifs);
  407. remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
  408. remove_proc_entry("fs/cifs", NULL);
  409. }
  410. static int cifsFYI_proc_show(struct seq_file *m, void *v)
  411. {
  412. seq_printf(m, "%d\n", cifsFYI);
  413. return 0;
  414. }
  415. static int cifsFYI_proc_open(struct inode *inode, struct file *file)
  416. {
  417. return single_open(file, cifsFYI_proc_show, NULL);
  418. }
  419. static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
  420. size_t count, loff_t *ppos)
  421. {
  422. char c;
  423. int rc;
  424. rc = get_user(c, buffer);
  425. if (rc)
  426. return rc;
  427. if (c == '0' || c == 'n' || c == 'N')
  428. cifsFYI = 0;
  429. else if (c == '1' || c == 'y' || c == 'Y')
  430. cifsFYI = 1;
  431. else if ((c > '1') && (c <= '9'))
  432. cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
  433. return count;
  434. }
  435. static const struct file_operations cifsFYI_proc_fops = {
  436. .owner = THIS_MODULE,
  437. .open = cifsFYI_proc_open,
  438. .read = seq_read,
  439. .llseek = seq_lseek,
  440. .release = single_release,
  441. .write = cifsFYI_proc_write,
  442. };
  443. static int cifs_oplock_proc_show(struct seq_file *m, void *v)
  444. {
  445. seq_printf(m, "%d\n", oplockEnabled);
  446. return 0;
  447. }
  448. static int cifs_oplock_proc_open(struct inode *inode, struct file *file)
  449. {
  450. return single_open(file, cifs_oplock_proc_show, NULL);
  451. }
  452. static ssize_t cifs_oplock_proc_write(struct file *file,
  453. const char __user *buffer, size_t count, loff_t *ppos)
  454. {
  455. char c;
  456. int rc;
  457. rc = get_user(c, buffer);
  458. if (rc)
  459. return rc;
  460. if (c == '0' || c == 'n' || c == 'N')
  461. oplockEnabled = 0;
  462. else if (c == '1' || c == 'y' || c == 'Y')
  463. oplockEnabled = 1;
  464. return count;
  465. }
  466. static const struct file_operations cifs_oplock_proc_fops = {
  467. .owner = THIS_MODULE,
  468. .open = cifs_oplock_proc_open,
  469. .read = seq_read,
  470. .llseek = seq_lseek,
  471. .release = single_release,
  472. .write = cifs_oplock_proc_write,
  473. };
  474. static int cifs_experimental_proc_show(struct seq_file *m, void *v)
  475. {
  476. seq_printf(m, "%d\n", experimEnabled);
  477. return 0;
  478. }
  479. static int cifs_experimental_proc_open(struct inode *inode, struct file *file)
  480. {
  481. return single_open(file, cifs_experimental_proc_show, NULL);
  482. }
  483. static ssize_t cifs_experimental_proc_write(struct file *file,
  484. const char __user *buffer, size_t count, loff_t *ppos)
  485. {
  486. char c;
  487. int rc;
  488. rc = get_user(c, buffer);
  489. if (rc)
  490. return rc;
  491. if (c == '0' || c == 'n' || c == 'N')
  492. experimEnabled = 0;
  493. else if (c == '1' || c == 'y' || c == 'Y')
  494. experimEnabled = 1;
  495. else if (c == '2')
  496. experimEnabled = 2;
  497. return count;
  498. }
  499. static const struct file_operations cifs_experimental_proc_fops = {
  500. .owner = THIS_MODULE,
  501. .open = cifs_experimental_proc_open,
  502. .read = seq_read,
  503. .llseek = seq_lseek,
  504. .release = single_release,
  505. .write = cifs_experimental_proc_write,
  506. };
  507. static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
  508. {
  509. seq_printf(m, "%d\n", linuxExtEnabled);
  510. return 0;
  511. }
  512. static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
  513. {
  514. return single_open(file, cifs_linux_ext_proc_show, NULL);
  515. }
  516. static ssize_t cifs_linux_ext_proc_write(struct file *file,
  517. const char __user *buffer, size_t count, loff_t *ppos)
  518. {
  519. char c;
  520. int rc;
  521. rc = get_user(c, buffer);
  522. if (rc)
  523. return rc;
  524. if (c == '0' || c == 'n' || c == 'N')
  525. linuxExtEnabled = 0;
  526. else if (c == '1' || c == 'y' || c == 'Y')
  527. linuxExtEnabled = 1;
  528. return count;
  529. }
  530. static const struct file_operations cifs_linux_ext_proc_fops = {
  531. .owner = THIS_MODULE,
  532. .open = cifs_linux_ext_proc_open,
  533. .read = seq_read,
  534. .llseek = seq_lseek,
  535. .release = single_release,
  536. .write = cifs_linux_ext_proc_write,
  537. };
  538. static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
  539. {
  540. seq_printf(m, "%d\n", lookupCacheEnabled);
  541. return 0;
  542. }
  543. static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
  544. {
  545. return single_open(file, cifs_lookup_cache_proc_show, NULL);
  546. }
  547. static ssize_t cifs_lookup_cache_proc_write(struct file *file,
  548. const char __user *buffer, size_t count, loff_t *ppos)
  549. {
  550. char c;
  551. int rc;
  552. rc = get_user(c, buffer);
  553. if (rc)
  554. return rc;
  555. if (c == '0' || c == 'n' || c == 'N')
  556. lookupCacheEnabled = 0;
  557. else if (c == '1' || c == 'y' || c == 'Y')
  558. lookupCacheEnabled = 1;
  559. return count;
  560. }
  561. static const struct file_operations cifs_lookup_cache_proc_fops = {
  562. .owner = THIS_MODULE,
  563. .open = cifs_lookup_cache_proc_open,
  564. .read = seq_read,
  565. .llseek = seq_lseek,
  566. .release = single_release,
  567. .write = cifs_lookup_cache_proc_write,
  568. };
  569. static int traceSMB_proc_show(struct seq_file *m, void *v)
  570. {
  571. seq_printf(m, "%d\n", traceSMB);
  572. return 0;
  573. }
  574. static int traceSMB_proc_open(struct inode *inode, struct file *file)
  575. {
  576. return single_open(file, traceSMB_proc_show, NULL);
  577. }
  578. static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
  579. size_t count, loff_t *ppos)
  580. {
  581. char c;
  582. int rc;
  583. rc = get_user(c, buffer);
  584. if (rc)
  585. return rc;
  586. if (c == '0' || c == 'n' || c == 'N')
  587. traceSMB = 0;
  588. else if (c == '1' || c == 'y' || c == 'Y')
  589. traceSMB = 1;
  590. return count;
  591. }
  592. static const struct file_operations traceSMB_proc_fops = {
  593. .owner = THIS_MODULE,
  594. .open = traceSMB_proc_open,
  595. .read = seq_read,
  596. .llseek = seq_lseek,
  597. .release = single_release,
  598. .write = traceSMB_proc_write,
  599. };
  600. static int cifs_multiuser_mount_proc_show(struct seq_file *m, void *v)
  601. {
  602. seq_printf(m, "%d\n", multiuser_mount);
  603. return 0;
  604. }
  605. static int cifs_multiuser_mount_proc_open(struct inode *inode, struct file *fh)
  606. {
  607. return single_open(fh, cifs_multiuser_mount_proc_show, NULL);
  608. }
  609. static ssize_t cifs_multiuser_mount_proc_write(struct file *file,
  610. const char __user *buffer, size_t count, loff_t *ppos)
  611. {
  612. char c;
  613. int rc;
  614. rc = get_user(c, buffer);
  615. if (rc)
  616. return rc;
  617. if (c == '0' || c == 'n' || c == 'N')
  618. multiuser_mount = 0;
  619. else if (c == '1' || c == 'y' || c == 'Y')
  620. multiuser_mount = 1;
  621. return count;
  622. }
  623. static const struct file_operations cifs_multiuser_mount_proc_fops = {
  624. .owner = THIS_MODULE,
  625. .open = cifs_multiuser_mount_proc_open,
  626. .read = seq_read,
  627. .llseek = seq_lseek,
  628. .release = single_release,
  629. .write = cifs_multiuser_mount_proc_write,
  630. };
  631. static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
  632. {
  633. seq_printf(m, "0x%x\n", extended_security);
  634. return 0;
  635. }
  636. static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
  637. {
  638. return single_open(file, cifs_security_flags_proc_show, NULL);
  639. }
  640. static ssize_t cifs_security_flags_proc_write(struct file *file,
  641. const char __user *buffer, size_t count, loff_t *ppos)
  642. {
  643. unsigned int flags;
  644. char flags_string[12];
  645. char c;
  646. if ((count < 1) || (count > 11))
  647. return -EINVAL;
  648. memset(flags_string, 0, 12);
  649. if (copy_from_user(flags_string, buffer, count))
  650. return -EFAULT;
  651. if (count < 3) {
  652. /* single char or single char followed by null */
  653. c = flags_string[0];
  654. if (c == '0' || c == 'n' || c == 'N') {
  655. extended_security = CIFSSEC_DEF; /* default */
  656. return count;
  657. } else if (c == '1' || c == 'y' || c == 'Y') {
  658. extended_security = CIFSSEC_MAX;
  659. return count;
  660. } else if (!isdigit(c)) {
  661. cERROR(1, ("invalid flag %c", c));
  662. return -EINVAL;
  663. }
  664. }
  665. /* else we have a number */
  666. flags = simple_strtoul(flags_string, NULL, 0);
  667. cFYI(1, ("sec flags 0x%x", flags));
  668. if (flags <= 0) {
  669. cERROR(1, ("invalid security flags %s", flags_string));
  670. return -EINVAL;
  671. }
  672. if (flags & ~CIFSSEC_MASK) {
  673. cERROR(1, ("attempt to set unsupported security flags 0x%x",
  674. flags & ~CIFSSEC_MASK));
  675. return -EINVAL;
  676. }
  677. /* flags look ok - update the global security flags for cifs module */
  678. extended_security = flags;
  679. if (extended_security & CIFSSEC_MUST_SIGN) {
  680. /* requiring signing implies signing is allowed */
  681. extended_security |= CIFSSEC_MAY_SIGN;
  682. cFYI(1, ("packet signing now required"));
  683. } else if ((extended_security & CIFSSEC_MAY_SIGN) == 0) {
  684. cFYI(1, ("packet signing disabled"));
  685. }
  686. /* BB should we turn on MAY flags for other MUST options? */
  687. return count;
  688. }
  689. static const struct file_operations cifs_security_flags_proc_fops = {
  690. .owner = THIS_MODULE,
  691. .open = cifs_security_flags_proc_open,
  692. .read = seq_read,
  693. .llseek = seq_lseek,
  694. .release = single_release,
  695. .write = cifs_security_flags_proc_write,
  696. };
  697. #else
  698. inline void cifs_proc_init(void)
  699. {
  700. }
  701. inline void cifs_proc_clean(void)
  702. {
  703. }
  704. #endif /* PROC_FS */