cifs_debug.c 21 KB

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