cifs_debug.c 21 KB

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