cifs_debug.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802
  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_posixopens, 0);
  244. atomic_set(&tcon->num_posixmkdirs, 0);
  245. atomic_set(&tcon->num_closes, 0);
  246. atomic_set(&tcon->num_deletes, 0);
  247. atomic_set(&tcon->num_mkdirs, 0);
  248. atomic_set(&tcon->num_rmdirs, 0);
  249. atomic_set(&tcon->num_renames, 0);
  250. atomic_set(&tcon->num_t2renames, 0);
  251. atomic_set(&tcon->num_ffirst, 0);
  252. atomic_set(&tcon->num_fnext, 0);
  253. atomic_set(&tcon->num_fclose, 0);
  254. atomic_set(&tcon->num_hardlinks, 0);
  255. atomic_set(&tcon->num_symlinks, 0);
  256. atomic_set(&tcon->num_locks, 0);
  257. }
  258. }
  259. }
  260. read_unlock(&cifs_tcp_ses_lock);
  261. }
  262. return count;
  263. }
  264. static int cifs_stats_proc_show(struct seq_file *m, void *v)
  265. {
  266. int i;
  267. struct list_head *tmp1, *tmp2, *tmp3;
  268. struct TCP_Server_Info *server;
  269. struct cifsSesInfo *ses;
  270. struct cifsTconInfo *tcon;
  271. seq_printf(m,
  272. "Resources in use\nCIFS Session: %d\n",
  273. sesInfoAllocCount.counter);
  274. seq_printf(m, "Share (unique mount targets): %d\n",
  275. tconInfoAllocCount.counter);
  276. seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
  277. bufAllocCount.counter,
  278. cifs_min_rcv + tcpSesAllocCount.counter);
  279. seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
  280. smBufAllocCount.counter, cifs_min_small);
  281. #ifdef CONFIG_CIFS_STATS2
  282. seq_printf(m, "Total Large %d Small %d Allocations\n",
  283. atomic_read(&totBufAllocCount),
  284. atomic_read(&totSmBufAllocCount));
  285. #endif /* CONFIG_CIFS_STATS2 */
  286. seq_printf(m, "Operations (MIDs): %d\n", midCount.counter);
  287. seq_printf(m,
  288. "\n%d session %d share reconnects\n",
  289. tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
  290. seq_printf(m,
  291. "Total vfs operations: %d maximum at one time: %d\n",
  292. GlobalCurrentXid, GlobalMaxActiveXid);
  293. i = 0;
  294. read_lock(&cifs_tcp_ses_lock);
  295. list_for_each(tmp1, &cifs_tcp_ses_list) {
  296. server = list_entry(tmp1, struct TCP_Server_Info,
  297. tcp_ses_list);
  298. list_for_each(tmp2, &server->smb_ses_list) {
  299. ses = list_entry(tmp2, struct cifsSesInfo,
  300. smb_ses_list);
  301. list_for_each(tmp3, &ses->tcon_list) {
  302. tcon = list_entry(tmp3,
  303. struct cifsTconInfo,
  304. tcon_list);
  305. i++;
  306. seq_printf(m, "\n%d) %s", i, tcon->treeName);
  307. if (tcon->need_reconnect)
  308. seq_puts(m, "\tDISCONNECTED ");
  309. seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
  310. atomic_read(&tcon->num_smbs_sent),
  311. atomic_read(&tcon->num_oplock_brks));
  312. seq_printf(m, "\nReads: %d Bytes: %lld",
  313. atomic_read(&tcon->num_reads),
  314. (long long)(tcon->bytes_read));
  315. seq_printf(m, "\nWrites: %d Bytes: %lld",
  316. atomic_read(&tcon->num_writes),
  317. (long long)(tcon->bytes_written));
  318. seq_printf(m, "\nFlushes: %d",
  319. atomic_read(&tcon->num_flushes));
  320. seq_printf(m, "\nLocks: %d HardLinks: %d "
  321. "Symlinks: %d",
  322. atomic_read(&tcon->num_locks),
  323. atomic_read(&tcon->num_hardlinks),
  324. atomic_read(&tcon->num_symlinks));
  325. seq_printf(m, "\nOpens: %d Closes: %d "
  326. "Deletes: %d",
  327. atomic_read(&tcon->num_opens),
  328. atomic_read(&tcon->num_closes),
  329. atomic_read(&tcon->num_deletes));
  330. seq_printf(m, "\nPosix Opens: %d "
  331. "Posix Mkdirs: %d",
  332. atomic_read(&tcon->num_posixopens),
  333. atomic_read(&tcon->num_posixmkdirs));
  334. seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
  335. atomic_read(&tcon->num_mkdirs),
  336. atomic_read(&tcon->num_rmdirs));
  337. seq_printf(m, "\nRenames: %d T2 Renames %d",
  338. atomic_read(&tcon->num_renames),
  339. atomic_read(&tcon->num_t2renames));
  340. seq_printf(m, "\nFindFirst: %d FNext %d "
  341. "FClose %d",
  342. atomic_read(&tcon->num_ffirst),
  343. atomic_read(&tcon->num_fnext),
  344. atomic_read(&tcon->num_fclose));
  345. }
  346. }
  347. }
  348. read_unlock(&cifs_tcp_ses_lock);
  349. seq_putc(m, '\n');
  350. return 0;
  351. }
  352. static int cifs_stats_proc_open(struct inode *inode, struct file *file)
  353. {
  354. return single_open(file, cifs_stats_proc_show, NULL);
  355. }
  356. static const struct file_operations cifs_stats_proc_fops = {
  357. .owner = THIS_MODULE,
  358. .open = cifs_stats_proc_open,
  359. .read = seq_read,
  360. .llseek = seq_lseek,
  361. .release = single_release,
  362. .write = cifs_stats_proc_write,
  363. };
  364. #endif /* STATS */
  365. static struct proc_dir_entry *proc_fs_cifs;
  366. static const struct file_operations cifsFYI_proc_fops;
  367. static const struct file_operations cifs_oplock_proc_fops;
  368. static const struct file_operations cifs_lookup_cache_proc_fops;
  369. static const struct file_operations traceSMB_proc_fops;
  370. static const struct file_operations cifs_multiuser_mount_proc_fops;
  371. static const struct file_operations cifs_security_flags_proc_fops;
  372. static const struct file_operations cifs_experimental_proc_fops;
  373. static const struct file_operations cifs_linux_ext_proc_fops;
  374. void
  375. cifs_proc_init(void)
  376. {
  377. proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
  378. if (proc_fs_cifs == NULL)
  379. return;
  380. proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
  381. #ifdef CONFIG_CIFS_STATS
  382. proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
  383. #endif /* STATS */
  384. proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
  385. proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
  386. proc_create("OplockEnabled", 0, proc_fs_cifs, &cifs_oplock_proc_fops);
  387. proc_create("Experimental", 0, proc_fs_cifs,
  388. &cifs_experimental_proc_fops);
  389. proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
  390. &cifs_linux_ext_proc_fops);
  391. proc_create("MultiuserMount", 0, proc_fs_cifs,
  392. &cifs_multiuser_mount_proc_fops);
  393. proc_create("SecurityFlags", 0, proc_fs_cifs,
  394. &cifs_security_flags_proc_fops);
  395. proc_create("LookupCacheEnabled", 0, proc_fs_cifs,
  396. &cifs_lookup_cache_proc_fops);
  397. }
  398. void
  399. cifs_proc_clean(void)
  400. {
  401. if (proc_fs_cifs == NULL)
  402. return;
  403. remove_proc_entry("DebugData", proc_fs_cifs);
  404. remove_proc_entry("cifsFYI", proc_fs_cifs);
  405. remove_proc_entry("traceSMB", proc_fs_cifs);
  406. #ifdef CONFIG_CIFS_STATS
  407. remove_proc_entry("Stats", proc_fs_cifs);
  408. #endif
  409. remove_proc_entry("MultiuserMount", proc_fs_cifs);
  410. remove_proc_entry("OplockEnabled", proc_fs_cifs);
  411. remove_proc_entry("SecurityFlags", proc_fs_cifs);
  412. remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
  413. remove_proc_entry("Experimental", proc_fs_cifs);
  414. remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
  415. remove_proc_entry("fs/cifs", NULL);
  416. }
  417. static int cifsFYI_proc_show(struct seq_file *m, void *v)
  418. {
  419. seq_printf(m, "%d\n", cifsFYI);
  420. return 0;
  421. }
  422. static int cifsFYI_proc_open(struct inode *inode, struct file *file)
  423. {
  424. return single_open(file, cifsFYI_proc_show, NULL);
  425. }
  426. static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
  427. size_t count, loff_t *ppos)
  428. {
  429. char c;
  430. int rc;
  431. rc = get_user(c, buffer);
  432. if (rc)
  433. return rc;
  434. if (c == '0' || c == 'n' || c == 'N')
  435. cifsFYI = 0;
  436. else if (c == '1' || c == 'y' || c == 'Y')
  437. cifsFYI = 1;
  438. else if ((c > '1') && (c <= '9'))
  439. cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
  440. return count;
  441. }
  442. static const struct file_operations cifsFYI_proc_fops = {
  443. .owner = THIS_MODULE,
  444. .open = cifsFYI_proc_open,
  445. .read = seq_read,
  446. .llseek = seq_lseek,
  447. .release = single_release,
  448. .write = cifsFYI_proc_write,
  449. };
  450. static int cifs_oplock_proc_show(struct seq_file *m, void *v)
  451. {
  452. seq_printf(m, "%d\n", oplockEnabled);
  453. return 0;
  454. }
  455. static int cifs_oplock_proc_open(struct inode *inode, struct file *file)
  456. {
  457. return single_open(file, cifs_oplock_proc_show, NULL);
  458. }
  459. static ssize_t cifs_oplock_proc_write(struct file *file,
  460. const char __user *buffer, size_t count, loff_t *ppos)
  461. {
  462. char c;
  463. int rc;
  464. rc = get_user(c, buffer);
  465. if (rc)
  466. return rc;
  467. if (c == '0' || c == 'n' || c == 'N')
  468. oplockEnabled = 0;
  469. else if (c == '1' || c == 'y' || c == 'Y')
  470. oplockEnabled = 1;
  471. return count;
  472. }
  473. static const struct file_operations cifs_oplock_proc_fops = {
  474. .owner = THIS_MODULE,
  475. .open = cifs_oplock_proc_open,
  476. .read = seq_read,
  477. .llseek = seq_lseek,
  478. .release = single_release,
  479. .write = cifs_oplock_proc_write,
  480. };
  481. static int cifs_experimental_proc_show(struct seq_file *m, void *v)
  482. {
  483. seq_printf(m, "%d\n", experimEnabled);
  484. return 0;
  485. }
  486. static int cifs_experimental_proc_open(struct inode *inode, struct file *file)
  487. {
  488. return single_open(file, cifs_experimental_proc_show, NULL);
  489. }
  490. static ssize_t cifs_experimental_proc_write(struct file *file,
  491. const char __user *buffer, size_t count, loff_t *ppos)
  492. {
  493. char c;
  494. int rc;
  495. rc = get_user(c, buffer);
  496. if (rc)
  497. return rc;
  498. if (c == '0' || c == 'n' || c == 'N')
  499. experimEnabled = 0;
  500. else if (c == '1' || c == 'y' || c == 'Y')
  501. experimEnabled = 1;
  502. else if (c == '2')
  503. experimEnabled = 2;
  504. return count;
  505. }
  506. static const struct file_operations cifs_experimental_proc_fops = {
  507. .owner = THIS_MODULE,
  508. .open = cifs_experimental_proc_open,
  509. .read = seq_read,
  510. .llseek = seq_lseek,
  511. .release = single_release,
  512. .write = cifs_experimental_proc_write,
  513. };
  514. static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
  515. {
  516. seq_printf(m, "%d\n", linuxExtEnabled);
  517. return 0;
  518. }
  519. static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
  520. {
  521. return single_open(file, cifs_linux_ext_proc_show, NULL);
  522. }
  523. static ssize_t cifs_linux_ext_proc_write(struct file *file,
  524. const char __user *buffer, size_t count, loff_t *ppos)
  525. {
  526. char c;
  527. int rc;
  528. rc = get_user(c, buffer);
  529. if (rc)
  530. return rc;
  531. if (c == '0' || c == 'n' || c == 'N')
  532. linuxExtEnabled = 0;
  533. else if (c == '1' || c == 'y' || c == 'Y')
  534. linuxExtEnabled = 1;
  535. return count;
  536. }
  537. static const struct file_operations cifs_linux_ext_proc_fops = {
  538. .owner = THIS_MODULE,
  539. .open = cifs_linux_ext_proc_open,
  540. .read = seq_read,
  541. .llseek = seq_lseek,
  542. .release = single_release,
  543. .write = cifs_linux_ext_proc_write,
  544. };
  545. static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
  546. {
  547. seq_printf(m, "%d\n", lookupCacheEnabled);
  548. return 0;
  549. }
  550. static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
  551. {
  552. return single_open(file, cifs_lookup_cache_proc_show, NULL);
  553. }
  554. static ssize_t cifs_lookup_cache_proc_write(struct file *file,
  555. const char __user *buffer, size_t count, loff_t *ppos)
  556. {
  557. char c;
  558. int rc;
  559. rc = get_user(c, buffer);
  560. if (rc)
  561. return rc;
  562. if (c == '0' || c == 'n' || c == 'N')
  563. lookupCacheEnabled = 0;
  564. else if (c == '1' || c == 'y' || c == 'Y')
  565. lookupCacheEnabled = 1;
  566. return count;
  567. }
  568. static const struct file_operations cifs_lookup_cache_proc_fops = {
  569. .owner = THIS_MODULE,
  570. .open = cifs_lookup_cache_proc_open,
  571. .read = seq_read,
  572. .llseek = seq_lseek,
  573. .release = single_release,
  574. .write = cifs_lookup_cache_proc_write,
  575. };
  576. static int traceSMB_proc_show(struct seq_file *m, void *v)
  577. {
  578. seq_printf(m, "%d\n", traceSMB);
  579. return 0;
  580. }
  581. static int traceSMB_proc_open(struct inode *inode, struct file *file)
  582. {
  583. return single_open(file, traceSMB_proc_show, NULL);
  584. }
  585. static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
  586. size_t count, loff_t *ppos)
  587. {
  588. char c;
  589. int rc;
  590. rc = get_user(c, buffer);
  591. if (rc)
  592. return rc;
  593. if (c == '0' || c == 'n' || c == 'N')
  594. traceSMB = 0;
  595. else if (c == '1' || c == 'y' || c == 'Y')
  596. traceSMB = 1;
  597. return count;
  598. }
  599. static const struct file_operations traceSMB_proc_fops = {
  600. .owner = THIS_MODULE,
  601. .open = traceSMB_proc_open,
  602. .read = seq_read,
  603. .llseek = seq_lseek,
  604. .release = single_release,
  605. .write = traceSMB_proc_write,
  606. };
  607. static int cifs_multiuser_mount_proc_show(struct seq_file *m, void *v)
  608. {
  609. seq_printf(m, "%d\n", multiuser_mount);
  610. return 0;
  611. }
  612. static int cifs_multiuser_mount_proc_open(struct inode *inode, struct file *fh)
  613. {
  614. return single_open(fh, cifs_multiuser_mount_proc_show, NULL);
  615. }
  616. static ssize_t cifs_multiuser_mount_proc_write(struct file *file,
  617. const char __user *buffer, size_t count, loff_t *ppos)
  618. {
  619. char c;
  620. int rc;
  621. rc = get_user(c, buffer);
  622. if (rc)
  623. return rc;
  624. if (c == '0' || c == 'n' || c == 'N')
  625. multiuser_mount = 0;
  626. else if (c == '1' || c == 'y' || c == 'Y')
  627. multiuser_mount = 1;
  628. return count;
  629. }
  630. static const struct file_operations cifs_multiuser_mount_proc_fops = {
  631. .owner = THIS_MODULE,
  632. .open = cifs_multiuser_mount_proc_open,
  633. .read = seq_read,
  634. .llseek = seq_lseek,
  635. .release = single_release,
  636. .write = cifs_multiuser_mount_proc_write,
  637. };
  638. static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
  639. {
  640. seq_printf(m, "0x%x\n", extended_security);
  641. return 0;
  642. }
  643. static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
  644. {
  645. return single_open(file, cifs_security_flags_proc_show, NULL);
  646. }
  647. static ssize_t cifs_security_flags_proc_write(struct file *file,
  648. const char __user *buffer, size_t count, loff_t *ppos)
  649. {
  650. unsigned int flags;
  651. char flags_string[12];
  652. char c;
  653. if ((count < 1) || (count > 11))
  654. return -EINVAL;
  655. memset(flags_string, 0, 12);
  656. if (copy_from_user(flags_string, buffer, count))
  657. return -EFAULT;
  658. if (count < 3) {
  659. /* single char or single char followed by null */
  660. c = flags_string[0];
  661. if (c == '0' || c == 'n' || c == 'N') {
  662. extended_security = CIFSSEC_DEF; /* default */
  663. return count;
  664. } else if (c == '1' || c == 'y' || c == 'Y') {
  665. extended_security = CIFSSEC_MAX;
  666. return count;
  667. } else if (!isdigit(c)) {
  668. cERROR(1, ("invalid flag %c", c));
  669. return -EINVAL;
  670. }
  671. }
  672. /* else we have a number */
  673. flags = simple_strtoul(flags_string, NULL, 0);
  674. cFYI(1, ("sec flags 0x%x", flags));
  675. if (flags <= 0) {
  676. cERROR(1, ("invalid security flags %s", flags_string));
  677. return -EINVAL;
  678. }
  679. if (flags & ~CIFSSEC_MASK) {
  680. cERROR(1, ("attempt to set unsupported security flags 0x%x",
  681. flags & ~CIFSSEC_MASK));
  682. return -EINVAL;
  683. }
  684. /* flags look ok - update the global security flags for cifs module */
  685. extended_security = flags;
  686. if (extended_security & CIFSSEC_MUST_SIGN) {
  687. /* requiring signing implies signing is allowed */
  688. extended_security |= CIFSSEC_MAY_SIGN;
  689. cFYI(1, ("packet signing now required"));
  690. } else if ((extended_security & CIFSSEC_MAY_SIGN) == 0) {
  691. cFYI(1, ("packet signing disabled"));
  692. }
  693. /* BB should we turn on MAY flags for other MUST options? */
  694. return count;
  695. }
  696. static const struct file_operations cifs_security_flags_proc_fops = {
  697. .owner = THIS_MODULE,
  698. .open = cifs_security_flags_proc_open,
  699. .read = seq_read,
  700. .llseek = seq_lseek,
  701. .release = single_release,
  702. .write = cifs_security_flags_proc_write,
  703. };
  704. #else
  705. inline void cifs_proc_init(void)
  706. {
  707. }
  708. inline void cifs_proc_clean(void)
  709. {
  710. }
  711. #endif /* PROC_FS */