cifs_debug.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797
  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, "\nFlushes: %d",
  317. atomic_read(&tcon->num_flushes));
  318. seq_printf(m, "\nLocks: %d HardLinks: %d "
  319. "Symlinks: %d",
  320. atomic_read(&tcon->num_locks),
  321. atomic_read(&tcon->num_hardlinks),
  322. atomic_read(&tcon->num_symlinks));
  323. seq_printf(m, "\nOpens: %d Closes: %d"
  324. "Deletes: %d",
  325. atomic_read(&tcon->num_opens),
  326. atomic_read(&tcon->num_closes),
  327. atomic_read(&tcon->num_deletes));
  328. seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
  329. atomic_read(&tcon->num_mkdirs),
  330. atomic_read(&tcon->num_rmdirs));
  331. seq_printf(m, "\nRenames: %d T2 Renames %d",
  332. atomic_read(&tcon->num_renames),
  333. atomic_read(&tcon->num_t2renames));
  334. seq_printf(m, "\nFindFirst: %d FNext %d "
  335. "FClose %d",
  336. atomic_read(&tcon->num_ffirst),
  337. atomic_read(&tcon->num_fnext),
  338. atomic_read(&tcon->num_fclose));
  339. }
  340. }
  341. }
  342. read_unlock(&cifs_tcp_ses_lock);
  343. seq_putc(m, '\n');
  344. return 0;
  345. }
  346. static int cifs_stats_proc_open(struct inode *inode, struct file *file)
  347. {
  348. return single_open(file, cifs_stats_proc_show, NULL);
  349. }
  350. static const struct file_operations cifs_stats_proc_fops = {
  351. .owner = THIS_MODULE,
  352. .open = cifs_stats_proc_open,
  353. .read = seq_read,
  354. .llseek = seq_lseek,
  355. .release = single_release,
  356. .write = cifs_stats_proc_write,
  357. };
  358. #endif /* STATS */
  359. static struct proc_dir_entry *proc_fs_cifs;
  360. static const struct file_operations cifsFYI_proc_fops;
  361. static const struct file_operations cifs_oplock_proc_fops;
  362. static const struct file_operations cifs_lookup_cache_proc_fops;
  363. static const struct file_operations traceSMB_proc_fops;
  364. static const struct file_operations cifs_multiuser_mount_proc_fops;
  365. static const struct file_operations cifs_security_flags_proc_fops;
  366. static const struct file_operations cifs_experimental_proc_fops;
  367. static const struct file_operations cifs_linux_ext_proc_fops;
  368. void
  369. cifs_proc_init(void)
  370. {
  371. proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
  372. if (proc_fs_cifs == NULL)
  373. return;
  374. proc_fs_cifs->owner = THIS_MODULE;
  375. proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
  376. #ifdef CONFIG_CIFS_STATS
  377. proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
  378. #endif /* STATS */
  379. proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
  380. proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
  381. proc_create("OplockEnabled", 0, proc_fs_cifs, &cifs_oplock_proc_fops);
  382. proc_create("Experimental", 0, proc_fs_cifs,
  383. &cifs_experimental_proc_fops);
  384. proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
  385. &cifs_linux_ext_proc_fops);
  386. proc_create("MultiuserMount", 0, proc_fs_cifs,
  387. &cifs_multiuser_mount_proc_fops);
  388. proc_create("SecurityFlags", 0, proc_fs_cifs,
  389. &cifs_security_flags_proc_fops);
  390. proc_create("LookupCacheEnabled", 0, proc_fs_cifs,
  391. &cifs_lookup_cache_proc_fops);
  392. }
  393. void
  394. cifs_proc_clean(void)
  395. {
  396. if (proc_fs_cifs == NULL)
  397. return;
  398. remove_proc_entry("DebugData", proc_fs_cifs);
  399. remove_proc_entry("cifsFYI", proc_fs_cifs);
  400. remove_proc_entry("traceSMB", proc_fs_cifs);
  401. #ifdef CONFIG_CIFS_STATS
  402. remove_proc_entry("Stats", proc_fs_cifs);
  403. #endif
  404. remove_proc_entry("MultiuserMount", proc_fs_cifs);
  405. remove_proc_entry("OplockEnabled", proc_fs_cifs);
  406. remove_proc_entry("SecurityFlags", proc_fs_cifs);
  407. remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
  408. remove_proc_entry("Experimental", proc_fs_cifs);
  409. remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
  410. remove_proc_entry("fs/cifs", NULL);
  411. }
  412. static int cifsFYI_proc_show(struct seq_file *m, void *v)
  413. {
  414. seq_printf(m, "%d\n", cifsFYI);
  415. return 0;
  416. }
  417. static int cifsFYI_proc_open(struct inode *inode, struct file *file)
  418. {
  419. return single_open(file, cifsFYI_proc_show, NULL);
  420. }
  421. static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
  422. size_t count, loff_t *ppos)
  423. {
  424. char c;
  425. int rc;
  426. rc = get_user(c, buffer);
  427. if (rc)
  428. return rc;
  429. if (c == '0' || c == 'n' || c == 'N')
  430. cifsFYI = 0;
  431. else if (c == '1' || c == 'y' || c == 'Y')
  432. cifsFYI = 1;
  433. else if ((c > '1') && (c <= '9'))
  434. cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
  435. return count;
  436. }
  437. static const struct file_operations cifsFYI_proc_fops = {
  438. .owner = THIS_MODULE,
  439. .open = cifsFYI_proc_open,
  440. .read = seq_read,
  441. .llseek = seq_lseek,
  442. .release = single_release,
  443. .write = cifsFYI_proc_write,
  444. };
  445. static int cifs_oplock_proc_show(struct seq_file *m, void *v)
  446. {
  447. seq_printf(m, "%d\n", oplockEnabled);
  448. return 0;
  449. }
  450. static int cifs_oplock_proc_open(struct inode *inode, struct file *file)
  451. {
  452. return single_open(file, cifs_oplock_proc_show, NULL);
  453. }
  454. static ssize_t cifs_oplock_proc_write(struct file *file,
  455. const char __user *buffer, size_t count, loff_t *ppos)
  456. {
  457. char c;
  458. int rc;
  459. rc = get_user(c, buffer);
  460. if (rc)
  461. return rc;
  462. if (c == '0' || c == 'n' || c == 'N')
  463. oplockEnabled = 0;
  464. else if (c == '1' || c == 'y' || c == 'Y')
  465. oplockEnabled = 1;
  466. return count;
  467. }
  468. static const struct file_operations cifs_oplock_proc_fops = {
  469. .owner = THIS_MODULE,
  470. .open = cifs_oplock_proc_open,
  471. .read = seq_read,
  472. .llseek = seq_lseek,
  473. .release = single_release,
  474. .write = cifs_oplock_proc_write,
  475. };
  476. static int cifs_experimental_proc_show(struct seq_file *m, void *v)
  477. {
  478. seq_printf(m, "%d\n", experimEnabled);
  479. return 0;
  480. }
  481. static int cifs_experimental_proc_open(struct inode *inode, struct file *file)
  482. {
  483. return single_open(file, cifs_experimental_proc_show, NULL);
  484. }
  485. static ssize_t cifs_experimental_proc_write(struct file *file,
  486. const char __user *buffer, size_t count, loff_t *ppos)
  487. {
  488. char c;
  489. int rc;
  490. rc = get_user(c, buffer);
  491. if (rc)
  492. return rc;
  493. if (c == '0' || c == 'n' || c == 'N')
  494. experimEnabled = 0;
  495. else if (c == '1' || c == 'y' || c == 'Y')
  496. experimEnabled = 1;
  497. else if (c == '2')
  498. experimEnabled = 2;
  499. return count;
  500. }
  501. static const struct file_operations cifs_experimental_proc_fops = {
  502. .owner = THIS_MODULE,
  503. .open = cifs_experimental_proc_open,
  504. .read = seq_read,
  505. .llseek = seq_lseek,
  506. .release = single_release,
  507. .write = cifs_experimental_proc_write,
  508. };
  509. static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
  510. {
  511. seq_printf(m, "%d\n", linuxExtEnabled);
  512. return 0;
  513. }
  514. static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
  515. {
  516. return single_open(file, cifs_linux_ext_proc_show, NULL);
  517. }
  518. static ssize_t cifs_linux_ext_proc_write(struct file *file,
  519. const char __user *buffer, size_t count, loff_t *ppos)
  520. {
  521. char c;
  522. int rc;
  523. rc = get_user(c, buffer);
  524. if (rc)
  525. return rc;
  526. if (c == '0' || c == 'n' || c == 'N')
  527. linuxExtEnabled = 0;
  528. else if (c == '1' || c == 'y' || c == 'Y')
  529. linuxExtEnabled = 1;
  530. return count;
  531. }
  532. static const struct file_operations cifs_linux_ext_proc_fops = {
  533. .owner = THIS_MODULE,
  534. .open = cifs_linux_ext_proc_open,
  535. .read = seq_read,
  536. .llseek = seq_lseek,
  537. .release = single_release,
  538. .write = cifs_linux_ext_proc_write,
  539. };
  540. static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
  541. {
  542. seq_printf(m, "%d\n", lookupCacheEnabled);
  543. return 0;
  544. }
  545. static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
  546. {
  547. return single_open(file, cifs_lookup_cache_proc_show, NULL);
  548. }
  549. static ssize_t cifs_lookup_cache_proc_write(struct file *file,
  550. const char __user *buffer, size_t count, loff_t *ppos)
  551. {
  552. char c;
  553. int rc;
  554. rc = get_user(c, buffer);
  555. if (rc)
  556. return rc;
  557. if (c == '0' || c == 'n' || c == 'N')
  558. lookupCacheEnabled = 0;
  559. else if (c == '1' || c == 'y' || c == 'Y')
  560. lookupCacheEnabled = 1;
  561. return count;
  562. }
  563. static const struct file_operations cifs_lookup_cache_proc_fops = {
  564. .owner = THIS_MODULE,
  565. .open = cifs_lookup_cache_proc_open,
  566. .read = seq_read,
  567. .llseek = seq_lseek,
  568. .release = single_release,
  569. .write = cifs_lookup_cache_proc_write,
  570. };
  571. static int traceSMB_proc_show(struct seq_file *m, void *v)
  572. {
  573. seq_printf(m, "%d\n", traceSMB);
  574. return 0;
  575. }
  576. static int traceSMB_proc_open(struct inode *inode, struct file *file)
  577. {
  578. return single_open(file, traceSMB_proc_show, NULL);
  579. }
  580. static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
  581. size_t count, loff_t *ppos)
  582. {
  583. char c;
  584. int rc;
  585. rc = get_user(c, buffer);
  586. if (rc)
  587. return rc;
  588. if (c == '0' || c == 'n' || c == 'N')
  589. traceSMB = 0;
  590. else if (c == '1' || c == 'y' || c == 'Y')
  591. traceSMB = 1;
  592. return count;
  593. }
  594. static const struct file_operations traceSMB_proc_fops = {
  595. .owner = THIS_MODULE,
  596. .open = traceSMB_proc_open,
  597. .read = seq_read,
  598. .llseek = seq_lseek,
  599. .release = single_release,
  600. .write = traceSMB_proc_write,
  601. };
  602. static int cifs_multiuser_mount_proc_show(struct seq_file *m, void *v)
  603. {
  604. seq_printf(m, "%d\n", multiuser_mount);
  605. return 0;
  606. }
  607. static int cifs_multiuser_mount_proc_open(struct inode *inode, struct file *fh)
  608. {
  609. return single_open(fh, cifs_multiuser_mount_proc_show, NULL);
  610. }
  611. static ssize_t cifs_multiuser_mount_proc_write(struct file *file,
  612. const char __user *buffer, size_t count, loff_t *ppos)
  613. {
  614. char c;
  615. int rc;
  616. rc = get_user(c, buffer);
  617. if (rc)
  618. return rc;
  619. if (c == '0' || c == 'n' || c == 'N')
  620. multiuser_mount = 0;
  621. else if (c == '1' || c == 'y' || c == 'Y')
  622. multiuser_mount = 1;
  623. return count;
  624. }
  625. static const struct file_operations cifs_multiuser_mount_proc_fops = {
  626. .owner = THIS_MODULE,
  627. .open = cifs_multiuser_mount_proc_open,
  628. .read = seq_read,
  629. .llseek = seq_lseek,
  630. .release = single_release,
  631. .write = cifs_multiuser_mount_proc_write,
  632. };
  633. static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
  634. {
  635. seq_printf(m, "0x%x\n", extended_security);
  636. return 0;
  637. }
  638. static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
  639. {
  640. return single_open(file, cifs_security_flags_proc_show, NULL);
  641. }
  642. static ssize_t cifs_security_flags_proc_write(struct file *file,
  643. const char __user *buffer, size_t count, loff_t *ppos)
  644. {
  645. unsigned int flags;
  646. char flags_string[12];
  647. char c;
  648. if ((count < 1) || (count > 11))
  649. return -EINVAL;
  650. memset(flags_string, 0, 12);
  651. if (copy_from_user(flags_string, buffer, count))
  652. return -EFAULT;
  653. if (count < 3) {
  654. /* single char or single char followed by null */
  655. c = flags_string[0];
  656. if (c == '0' || c == 'n' || c == 'N') {
  657. extended_security = CIFSSEC_DEF; /* default */
  658. return count;
  659. } else if (c == '1' || c == 'y' || c == 'Y') {
  660. extended_security = CIFSSEC_MAX;
  661. return count;
  662. } else if (!isdigit(c)) {
  663. cERROR(1, ("invalid flag %c", c));
  664. return -EINVAL;
  665. }
  666. }
  667. /* else we have a number */
  668. flags = simple_strtoul(flags_string, NULL, 0);
  669. cFYI(1, ("sec flags 0x%x", flags));
  670. if (flags <= 0) {
  671. cERROR(1, ("invalid security flags %s", flags_string));
  672. return -EINVAL;
  673. }
  674. if (flags & ~CIFSSEC_MASK) {
  675. cERROR(1, ("attempt to set unsupported security flags 0x%x",
  676. flags & ~CIFSSEC_MASK));
  677. return -EINVAL;
  678. }
  679. /* flags look ok - update the global security flags for cifs module */
  680. extended_security = flags;
  681. if (extended_security & CIFSSEC_MUST_SIGN) {
  682. /* requiring signing implies signing is allowed */
  683. extended_security |= CIFSSEC_MAY_SIGN;
  684. cFYI(1, ("packet signing now required"));
  685. } else if ((extended_security & CIFSSEC_MAY_SIGN) == 0) {
  686. cFYI(1, ("packet signing disabled"));
  687. }
  688. /* BB should we turn on MAY flags for other MUST options? */
  689. return count;
  690. }
  691. static const struct file_operations cifs_security_flags_proc_fops = {
  692. .owner = THIS_MODULE,
  693. .open = cifs_security_flags_proc_open,
  694. .read = seq_read,
  695. .llseek = seq_lseek,
  696. .release = single_release,
  697. .write = cifs_security_flags_proc_write,
  698. };
  699. #else
  700. inline void cifs_proc_init(void)
  701. {
  702. }
  703. inline void cifs_proc_clean(void)
  704. {
  705. }
  706. #endif /* PROC_FS */