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