cifs_debug.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774
  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 *tmp;
  103. struct list_head *tmp1;
  104. struct mid_q_entry *mid_entry;
  105. struct cifsSesInfo *ses;
  106. struct cifsTconInfo *tcon;
  107. int i;
  108. seq_puts(m,
  109. "Display Internal CIFS Data Structures for Debugging\n"
  110. "---------------------------------------------------\n");
  111. seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
  112. seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
  113. seq_printf(m, "Servers:");
  114. i = 0;
  115. read_lock(&GlobalSMBSeslock);
  116. list_for_each(tmp, &GlobalSMBSessionList) {
  117. i++;
  118. ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
  119. if ((ses->serverDomain == NULL) || (ses->serverOS == NULL) ||
  120. (ses->serverNOS == NULL)) {
  121. seq_printf(m, "\nentry for %s not fully "
  122. "displayed\n\t", ses->serverName);
  123. } else {
  124. seq_printf(m,
  125. "\n%d) Name: %s Domain: %s Mounts: %d OS:"
  126. " %s \n\tNOS: %s\tCapability: 0x%x\n\tSMB"
  127. " session status: %d\t",
  128. i, ses->serverName, ses->serverDomain,
  129. atomic_read(&ses->inUse),
  130. ses->serverOS, ses->serverNOS,
  131. ses->capabilities, ses->status);
  132. }
  133. if (ses->server) {
  134. seq_printf(m, "TCP status: %d\n\tLocal Users To "
  135. "Server: %d SecMode: 0x%x Req On Wire: %d",
  136. ses->server->tcpStatus,
  137. atomic_read(&ses->server->socketUseCount),
  138. ses->server->secMode,
  139. atomic_read(&ses->server->inFlight));
  140. #ifdef CONFIG_CIFS_STATS2
  141. seq_printf(m, " In Send: %d In MaxReq Wait: %d",
  142. atomic_read(&ses->server->inSend),
  143. atomic_read(&ses->server->num_waiters));
  144. #endif
  145. seq_puts(m, "\nMIDs:\n");
  146. spin_lock(&GlobalMid_Lock);
  147. list_for_each(tmp1, &ses->server->pending_mid_q) {
  148. mid_entry = list_entry(tmp1, struct
  149. mid_q_entry,
  150. qhead);
  151. seq_printf(m, "State: %d com: %d pid:"
  152. " %d tsk: %p mid %d\n",
  153. mid_entry->midState,
  154. (int)mid_entry->command,
  155. mid_entry->pid,
  156. mid_entry->tsk,
  157. mid_entry->mid);
  158. }
  159. spin_unlock(&GlobalMid_Lock);
  160. }
  161. }
  162. read_unlock(&GlobalSMBSeslock);
  163. seq_putc(m, '\n');
  164. seq_puts(m, "Shares:");
  165. i = 0;
  166. read_lock(&GlobalSMBSeslock);
  167. list_for_each(tmp, &GlobalTreeConnectionList) {
  168. __u32 dev_type;
  169. i++;
  170. tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
  171. dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
  172. seq_printf(m, "\n%d) %s Uses: %d ", i,
  173. tcon->treeName, atomic_read(&tcon->useCount));
  174. if (tcon->nativeFileSystem) {
  175. seq_printf(m, "Type: %s ",
  176. tcon->nativeFileSystem);
  177. }
  178. seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x"
  179. "\nPathComponentMax: %d Status: %d",
  180. le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
  181. le32_to_cpu(tcon->fsAttrInfo.Attributes),
  182. le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
  183. tcon->tidStatus);
  184. if (dev_type == FILE_DEVICE_DISK)
  185. seq_puts(m, " type: DISK ");
  186. else if (dev_type == FILE_DEVICE_CD_ROM)
  187. seq_puts(m, " type: CDROM ");
  188. else
  189. seq_printf(m, " type: %d ", dev_type);
  190. if (tcon->tidStatus == CifsNeedReconnect)
  191. seq_puts(m, "\tDISCONNECTED ");
  192. }
  193. read_unlock(&GlobalSMBSeslock);
  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 *tmp;
  216. struct cifsTconInfo *tcon;
  217. rc = get_user(c, buffer);
  218. if (rc)
  219. return rc;
  220. if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
  221. read_lock(&GlobalSMBSeslock);
  222. #ifdef CONFIG_CIFS_STATS2
  223. atomic_set(&totBufAllocCount, 0);
  224. atomic_set(&totSmBufAllocCount, 0);
  225. #endif /* CONFIG_CIFS_STATS2 */
  226. list_for_each(tmp, &GlobalTreeConnectionList) {
  227. tcon = list_entry(tmp, struct cifsTconInfo,
  228. cifsConnectionList);
  229. atomic_set(&tcon->num_smbs_sent, 0);
  230. atomic_set(&tcon->num_writes, 0);
  231. atomic_set(&tcon->num_reads, 0);
  232. atomic_set(&tcon->num_oplock_brks, 0);
  233. atomic_set(&tcon->num_opens, 0);
  234. atomic_set(&tcon->num_closes, 0);
  235. atomic_set(&tcon->num_deletes, 0);
  236. atomic_set(&tcon->num_mkdirs, 0);
  237. atomic_set(&tcon->num_rmdirs, 0);
  238. atomic_set(&tcon->num_renames, 0);
  239. atomic_set(&tcon->num_t2renames, 0);
  240. atomic_set(&tcon->num_ffirst, 0);
  241. atomic_set(&tcon->num_fnext, 0);
  242. atomic_set(&tcon->num_fclose, 0);
  243. atomic_set(&tcon->num_hardlinks, 0);
  244. atomic_set(&tcon->num_symlinks, 0);
  245. atomic_set(&tcon->num_locks, 0);
  246. }
  247. read_unlock(&GlobalSMBSeslock);
  248. }
  249. return count;
  250. }
  251. static int cifs_stats_proc_show(struct seq_file *m, void *v)
  252. {
  253. int i;
  254. struct list_head *tmp;
  255. struct cifsTconInfo *tcon;
  256. seq_printf(m,
  257. "Resources in use\nCIFS Session: %d\n",
  258. sesInfoAllocCount.counter);
  259. seq_printf(m, "Share (unique mount targets): %d\n",
  260. tconInfoAllocCount.counter);
  261. seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
  262. bufAllocCount.counter,
  263. cifs_min_rcv + tcpSesAllocCount.counter);
  264. seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
  265. smBufAllocCount.counter, cifs_min_small);
  266. #ifdef CONFIG_CIFS_STATS2
  267. seq_printf(m, "Total Large %d Small %d Allocations\n",
  268. atomic_read(&totBufAllocCount),
  269. atomic_read(&totSmBufAllocCount));
  270. #endif /* CONFIG_CIFS_STATS2 */
  271. seq_printf(m, "Operations (MIDs): %d\n", midCount.counter);
  272. seq_printf(m,
  273. "\n%d session %d share reconnects\n",
  274. tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
  275. seq_printf(m,
  276. "Total vfs operations: %d maximum at one time: %d\n",
  277. GlobalCurrentXid, GlobalMaxActiveXid);
  278. i = 0;
  279. read_lock(&GlobalSMBSeslock);
  280. list_for_each(tmp, &GlobalTreeConnectionList) {
  281. i++;
  282. tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
  283. seq_printf(m, "\n%d) %s", i, tcon->treeName);
  284. if (tcon->tidStatus == CifsNeedReconnect)
  285. seq_puts(m, "\tDISCONNECTED ");
  286. seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
  287. atomic_read(&tcon->num_smbs_sent),
  288. atomic_read(&tcon->num_oplock_brks));
  289. seq_printf(m, "\nReads: %d Bytes: %lld",
  290. atomic_read(&tcon->num_reads),
  291. (long long)(tcon->bytes_read));
  292. seq_printf(m, "\nWrites: %d Bytes: %lld",
  293. atomic_read(&tcon->num_writes),
  294. (long long)(tcon->bytes_written));
  295. seq_printf(m,
  296. "\nLocks: %d HardLinks: %d Symlinks: %d",
  297. atomic_read(&tcon->num_locks),
  298. atomic_read(&tcon->num_hardlinks),
  299. atomic_read(&tcon->num_symlinks));
  300. seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
  301. atomic_read(&tcon->num_opens),
  302. atomic_read(&tcon->num_closes),
  303. atomic_read(&tcon->num_deletes));
  304. seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
  305. atomic_read(&tcon->num_mkdirs),
  306. atomic_read(&tcon->num_rmdirs));
  307. seq_printf(m, "\nRenames: %d T2 Renames %d",
  308. atomic_read(&tcon->num_renames),
  309. atomic_read(&tcon->num_t2renames));
  310. seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
  311. atomic_read(&tcon->num_ffirst),
  312. atomic_read(&tcon->num_fnext),
  313. atomic_read(&tcon->num_fclose));
  314. }
  315. read_unlock(&GlobalSMBSeslock);
  316. seq_putc(m, '\n');
  317. return 0;
  318. }
  319. static int cifs_stats_proc_open(struct inode *inode, struct file *file)
  320. {
  321. return single_open(file, cifs_stats_proc_show, NULL);
  322. }
  323. static const struct file_operations cifs_stats_proc_fops = {
  324. .owner = THIS_MODULE,
  325. .open = cifs_stats_proc_open,
  326. .read = seq_read,
  327. .llseek = seq_lseek,
  328. .release = single_release,
  329. .write = cifs_stats_proc_write,
  330. };
  331. #endif /* STATS */
  332. static struct proc_dir_entry *proc_fs_cifs;
  333. static const struct file_operations cifsFYI_proc_fops;
  334. static const struct file_operations cifs_oplock_proc_fops;
  335. static const struct file_operations cifs_lookup_cache_proc_fops;
  336. static const struct file_operations traceSMB_proc_fops;
  337. static const struct file_operations cifs_multiuser_mount_proc_fops;
  338. static const struct file_operations cifs_security_flags_proc_fops;
  339. static const struct file_operations cifs_experimental_proc_fops;
  340. static const struct file_operations cifs_linux_ext_proc_fops;
  341. void
  342. cifs_proc_init(void)
  343. {
  344. proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
  345. if (proc_fs_cifs == NULL)
  346. return;
  347. proc_fs_cifs->owner = THIS_MODULE;
  348. proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
  349. #ifdef CONFIG_CIFS_STATS
  350. proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
  351. #endif /* STATS */
  352. proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
  353. proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
  354. proc_create("OplockEnabled", 0, proc_fs_cifs, &cifs_oplock_proc_fops);
  355. proc_create("Experimental", 0, proc_fs_cifs,
  356. &cifs_experimental_proc_fops);
  357. proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
  358. &cifs_linux_ext_proc_fops);
  359. proc_create("MultiuserMount", 0, proc_fs_cifs,
  360. &cifs_multiuser_mount_proc_fops);
  361. proc_create("SecurityFlags", 0, proc_fs_cifs,
  362. &cifs_security_flags_proc_fops);
  363. proc_create("LookupCacheEnabled", 0, proc_fs_cifs,
  364. &cifs_lookup_cache_proc_fops);
  365. }
  366. void
  367. cifs_proc_clean(void)
  368. {
  369. if (proc_fs_cifs == NULL)
  370. return;
  371. remove_proc_entry("DebugData", proc_fs_cifs);
  372. remove_proc_entry("cifsFYI", proc_fs_cifs);
  373. remove_proc_entry("traceSMB", proc_fs_cifs);
  374. #ifdef CONFIG_CIFS_STATS
  375. remove_proc_entry("Stats", proc_fs_cifs);
  376. #endif
  377. remove_proc_entry("MultiuserMount", proc_fs_cifs);
  378. remove_proc_entry("OplockEnabled", proc_fs_cifs);
  379. remove_proc_entry("SecurityFlags", proc_fs_cifs);
  380. remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
  381. remove_proc_entry("Experimental", proc_fs_cifs);
  382. remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
  383. remove_proc_entry("fs/cifs", NULL);
  384. }
  385. static int cifsFYI_proc_show(struct seq_file *m, void *v)
  386. {
  387. seq_printf(m, "%d\n", cifsFYI);
  388. return 0;
  389. }
  390. static int cifsFYI_proc_open(struct inode *inode, struct file *file)
  391. {
  392. return single_open(file, cifsFYI_proc_show, NULL);
  393. }
  394. static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
  395. size_t count, loff_t *ppos)
  396. {
  397. char c;
  398. int rc;
  399. rc = get_user(c, buffer);
  400. if (rc)
  401. return rc;
  402. if (c == '0' || c == 'n' || c == 'N')
  403. cifsFYI = 0;
  404. else if (c == '1' || c == 'y' || c == 'Y')
  405. cifsFYI = 1;
  406. else if ((c > '1') && (c <= '9'))
  407. cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
  408. return count;
  409. }
  410. static const struct file_operations cifsFYI_proc_fops = {
  411. .owner = THIS_MODULE,
  412. .open = cifsFYI_proc_open,
  413. .read = seq_read,
  414. .llseek = seq_lseek,
  415. .release = single_release,
  416. .write = cifsFYI_proc_write,
  417. };
  418. static int cifs_oplock_proc_show(struct seq_file *m, void *v)
  419. {
  420. seq_printf(m, "%d\n", oplockEnabled);
  421. return 0;
  422. }
  423. static int cifs_oplock_proc_open(struct inode *inode, struct file *file)
  424. {
  425. return single_open(file, cifs_oplock_proc_show, NULL);
  426. }
  427. static ssize_t cifs_oplock_proc_write(struct file *file,
  428. const char __user *buffer, size_t count, loff_t *ppos)
  429. {
  430. char c;
  431. int rc;
  432. rc = get_user(c, buffer);
  433. if (rc)
  434. return rc;
  435. if (c == '0' || c == 'n' || c == 'N')
  436. oplockEnabled = 0;
  437. else if (c == '1' || c == 'y' || c == 'Y')
  438. oplockEnabled = 1;
  439. return count;
  440. }
  441. static const struct file_operations cifs_oplock_proc_fops = {
  442. .owner = THIS_MODULE,
  443. .open = cifs_oplock_proc_open,
  444. .read = seq_read,
  445. .llseek = seq_lseek,
  446. .release = single_release,
  447. .write = cifs_oplock_proc_write,
  448. };
  449. static int cifs_experimental_proc_show(struct seq_file *m, void *v)
  450. {
  451. seq_printf(m, "%d\n", experimEnabled);
  452. return 0;
  453. }
  454. static int cifs_experimental_proc_open(struct inode *inode, struct file *file)
  455. {
  456. return single_open(file, cifs_experimental_proc_show, NULL);
  457. }
  458. static ssize_t cifs_experimental_proc_write(struct file *file,
  459. const char __user *buffer, size_t count, loff_t *ppos)
  460. {
  461. char c;
  462. int rc;
  463. rc = get_user(c, buffer);
  464. if (rc)
  465. return rc;
  466. if (c == '0' || c == 'n' || c == 'N')
  467. experimEnabled = 0;
  468. else if (c == '1' || c == 'y' || c == 'Y')
  469. experimEnabled = 1;
  470. else if (c == '2')
  471. experimEnabled = 2;
  472. return count;
  473. }
  474. static const struct file_operations cifs_experimental_proc_fops = {
  475. .owner = THIS_MODULE,
  476. .open = cifs_experimental_proc_open,
  477. .read = seq_read,
  478. .llseek = seq_lseek,
  479. .release = single_release,
  480. .write = cifs_experimental_proc_write,
  481. };
  482. static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
  483. {
  484. seq_printf(m, "%d\n", linuxExtEnabled);
  485. return 0;
  486. }
  487. static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
  488. {
  489. return single_open(file, cifs_linux_ext_proc_show, NULL);
  490. }
  491. static ssize_t cifs_linux_ext_proc_write(struct file *file,
  492. const char __user *buffer, size_t count, loff_t *ppos)
  493. {
  494. char c;
  495. int rc;
  496. rc = get_user(c, buffer);
  497. if (rc)
  498. return rc;
  499. if (c == '0' || c == 'n' || c == 'N')
  500. linuxExtEnabled = 0;
  501. else if (c == '1' || c == 'y' || c == 'Y')
  502. linuxExtEnabled = 1;
  503. return count;
  504. }
  505. static const struct file_operations cifs_linux_ext_proc_fops = {
  506. .owner = THIS_MODULE,
  507. .open = cifs_linux_ext_proc_open,
  508. .read = seq_read,
  509. .llseek = seq_lseek,
  510. .release = single_release,
  511. .write = cifs_linux_ext_proc_write,
  512. };
  513. static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
  514. {
  515. seq_printf(m, "%d\n", lookupCacheEnabled);
  516. return 0;
  517. }
  518. static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
  519. {
  520. return single_open(file, cifs_lookup_cache_proc_show, NULL);
  521. }
  522. static ssize_t cifs_lookup_cache_proc_write(struct file *file,
  523. const char __user *buffer, size_t count, loff_t *ppos)
  524. {
  525. char c;
  526. int rc;
  527. rc = get_user(c, buffer);
  528. if (rc)
  529. return rc;
  530. if (c == '0' || c == 'n' || c == 'N')
  531. lookupCacheEnabled = 0;
  532. else if (c == '1' || c == 'y' || c == 'Y')
  533. lookupCacheEnabled = 1;
  534. return count;
  535. }
  536. static const struct file_operations cifs_lookup_cache_proc_fops = {
  537. .owner = THIS_MODULE,
  538. .open = cifs_lookup_cache_proc_open,
  539. .read = seq_read,
  540. .llseek = seq_lseek,
  541. .release = single_release,
  542. .write = cifs_lookup_cache_proc_write,
  543. };
  544. static int traceSMB_proc_show(struct seq_file *m, void *v)
  545. {
  546. seq_printf(m, "%d\n", traceSMB);
  547. return 0;
  548. }
  549. static int traceSMB_proc_open(struct inode *inode, struct file *file)
  550. {
  551. return single_open(file, traceSMB_proc_show, NULL);
  552. }
  553. static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
  554. size_t count, loff_t *ppos)
  555. {
  556. char c;
  557. int rc;
  558. rc = get_user(c, buffer);
  559. if (rc)
  560. return rc;
  561. if (c == '0' || c == 'n' || c == 'N')
  562. traceSMB = 0;
  563. else if (c == '1' || c == 'y' || c == 'Y')
  564. traceSMB = 1;
  565. return count;
  566. }
  567. static const struct file_operations traceSMB_proc_fops = {
  568. .owner = THIS_MODULE,
  569. .open = traceSMB_proc_open,
  570. .read = seq_read,
  571. .llseek = seq_lseek,
  572. .release = single_release,
  573. .write = traceSMB_proc_write,
  574. };
  575. static int cifs_multiuser_mount_proc_show(struct seq_file *m, void *v)
  576. {
  577. seq_printf(m, "%d\n", multiuser_mount);
  578. return 0;
  579. }
  580. static int cifs_multiuser_mount_proc_open(struct inode *inode, struct file *fh)
  581. {
  582. return single_open(fh, cifs_multiuser_mount_proc_show, NULL);
  583. }
  584. static ssize_t cifs_multiuser_mount_proc_write(struct file *file,
  585. const char __user *buffer, size_t count, loff_t *ppos)
  586. {
  587. char c;
  588. int rc;
  589. rc = get_user(c, buffer);
  590. if (rc)
  591. return rc;
  592. if (c == '0' || c == 'n' || c == 'N')
  593. multiuser_mount = 0;
  594. else if (c == '1' || c == 'y' || c == 'Y')
  595. multiuser_mount = 1;
  596. return count;
  597. }
  598. static const struct file_operations cifs_multiuser_mount_proc_fops = {
  599. .owner = THIS_MODULE,
  600. .open = cifs_multiuser_mount_proc_open,
  601. .read = seq_read,
  602. .llseek = seq_lseek,
  603. .release = single_release,
  604. .write = cifs_multiuser_mount_proc_write,
  605. };
  606. static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
  607. {
  608. seq_printf(m, "0x%x\n", extended_security);
  609. return 0;
  610. }
  611. static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
  612. {
  613. return single_open(file, cifs_security_flags_proc_show, NULL);
  614. }
  615. static ssize_t cifs_security_flags_proc_write(struct file *file,
  616. const char __user *buffer, size_t count, loff_t *ppos)
  617. {
  618. unsigned int flags;
  619. char flags_string[12];
  620. char c;
  621. if ((count < 1) || (count > 11))
  622. return -EINVAL;
  623. memset(flags_string, 0, 12);
  624. if (copy_from_user(flags_string, buffer, count))
  625. return -EFAULT;
  626. if (count < 3) {
  627. /* single char or single char followed by null */
  628. c = flags_string[0];
  629. if (c == '0' || c == 'n' || c == 'N') {
  630. extended_security = CIFSSEC_DEF; /* default */
  631. return count;
  632. } else if (c == '1' || c == 'y' || c == 'Y') {
  633. extended_security = CIFSSEC_MAX;
  634. return count;
  635. } else if (!isdigit(c)) {
  636. cERROR(1, ("invalid flag %c", c));
  637. return -EINVAL;
  638. }
  639. }
  640. /* else we have a number */
  641. flags = simple_strtoul(flags_string, NULL, 0);
  642. cFYI(1, ("sec flags 0x%x", flags));
  643. if (flags <= 0) {
  644. cERROR(1, ("invalid security flags %s", flags_string));
  645. return -EINVAL;
  646. }
  647. if (flags & ~CIFSSEC_MASK) {
  648. cERROR(1, ("attempt to set unsupported security flags 0x%x",
  649. flags & ~CIFSSEC_MASK));
  650. return -EINVAL;
  651. }
  652. /* flags look ok - update the global security flags for cifs module */
  653. extended_security = flags;
  654. if (extended_security & CIFSSEC_MUST_SIGN) {
  655. /* requiring signing implies signing is allowed */
  656. extended_security |= CIFSSEC_MAY_SIGN;
  657. cFYI(1, ("packet signing now required"));
  658. } else if ((extended_security & CIFSSEC_MAY_SIGN) == 0) {
  659. cFYI(1, ("packet signing disabled"));
  660. }
  661. /* BB should we turn on MAY flags for other MUST options? */
  662. return count;
  663. }
  664. static const struct file_operations cifs_security_flags_proc_fops = {
  665. .owner = THIS_MODULE,
  666. .open = cifs_security_flags_proc_open,
  667. .read = seq_read,
  668. .llseek = seq_lseek,
  669. .release = single_release,
  670. .write = cifs_security_flags_proc_write,
  671. };
  672. #else
  673. inline void cifs_proc_init(void)
  674. {
  675. }
  676. inline void cifs_proc_clean(void)
  677. {
  678. }
  679. #endif /* PROC_FS */