Merge tag 'v3.10.55' into update
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / fs / cifs / cifs_debug.c
CommitLineData
1da177e4
LT
1/*
2 * fs/cifs_debug.c
3 *
b8643e1b 4 * Copyright (C) International Business Machines Corp., 2000,2005
1da177e4
LT
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
221601c3 10 * the Free Software Foundation; either version 2 of the License, or
1da177e4 11 * (at your option) any later version.
221601c3 12 *
1da177e4
LT
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
221601c3 19 * along with this program; if not, write to the Free Software
1da177e4
LT
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"
6c91d362 32#include "cifsfs.h"
1da177e4
LT
33
34void
35cifs_dump_mem(char *label, void *data, int length)
36{
37 int i, j;
38 int *intptr = data;
39 char *charptr = data;
40 char buf[10], line[80];
41
221601c3 42 printk(KERN_DEBUG "%s: dump of %d bytes of data at 0x%p\n",
1da177e4
LT
43 label, length, data);
44 for (i = 0; i < length; i += 16) {
45 line[0] = 0;
46 for (j = 0; (j < 4) && (i + j * 4 < length); j++) {
47 sprintf(buf, " %08x", intptr[i / 4 + j]);
48 strcat(line, buf);
49 }
50 buf[0] = ' ';
51 buf[2] = 0;
52 for (j = 0; (j < 16) && (i + j < length); j++) {
53 buf[1] = isprint(charptr[i + j]) ? charptr[i + j] : '.';
54 strcat(line, buf);
55 }
56 printk(KERN_DEBUG "%s\n", line);
57 }
58}
59
f96637be
JP
60#ifdef CONFIG_CIFS_DEBUG
61void cifs_vfs_err(const char *fmt, ...)
62{
63 struct va_format vaf;
64 va_list args;
65
66 va_start(args, fmt);
67
68 vaf.fmt = fmt;
69 vaf.va = &args;
70
71 printk(KERN_ERR "CIFS VFS: %pV", &vaf);
72
73 va_end(args);
74}
75#endif
76
d4e4854f 77void cifs_dump_detail(void *buf)
3979877e 78{
8aa26f3e 79#ifdef CONFIG_CIFS_DEBUG2
d4e4854f
PS
80 struct smb_hdr *smb = (struct smb_hdr *)buf;
81
f96637be
JP
82 cifs_dbg(VFS, "Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d\n",
83 smb->Command, smb->Status.CifsError,
84 smb->Flags, smb->Flags2, smb->Mid, smb->Pid);
85 cifs_dbg(VFS, "smb buf %p len %u\n", smb, smbCalcSize(smb));
8aa26f3e 86#endif /* CONFIG_CIFS_DEBUG2 */
3979877e
SF
87}
88
ffdd6e4d 89void cifs_dump_mids(struct TCP_Server_Info *server)
3979877e 90{
8aa26f3e 91#ifdef CONFIG_CIFS_DEBUG2
3979877e 92 struct list_head *tmp;
ffdd6e4d 93 struct mid_q_entry *mid_entry;
3979877e 94
221601c3 95 if (server == NULL)
3979877e
SF
96 return;
97
f96637be 98 cifs_dbg(VFS, "Dump pending requests:\n");
3979877e
SF
99 spin_lock(&GlobalMid_Lock);
100 list_for_each(tmp, &server->pending_mid_q) {
101 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
f96637be
JP
102 cifs_dbg(VFS, "State: %d Cmd: %d Pid: %d Cbdata: %p Mid %llu\n",
103 mid_entry->mid_state,
104 le16_to_cpu(mid_entry->command),
105 mid_entry->pid,
106 mid_entry->callback_data,
107 mid_entry->mid);
3979877e 108#ifdef CONFIG_CIFS_STATS2
f96637be
JP
109 cifs_dbg(VFS, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n",
110 mid_entry->large_buf,
111 mid_entry->resp_buf,
112 mid_entry->when_received,
113 jiffies);
3979877e 114#endif /* STATS2 */
f96637be
JP
115 cifs_dbg(VFS, "IsMult: %d IsEnd: %d\n",
116 mid_entry->multiRsp, mid_entry->multiEnd);
ad8b15f0
SF
117 if (mid_entry->resp_buf) {
118 cifs_dump_detail(mid_entry->resp_buf);
119 cifs_dump_mem("existing buf: ",
120 mid_entry->resp_buf, 62);
3979877e
SF
121 }
122 }
123 spin_unlock(&GlobalMid_Lock);
3979877e 124#endif /* CONFIG_CIFS_DEBUG2 */
8aa26f3e 125}
3979877e 126
1da177e4 127#ifdef CONFIG_PROC_FS
f984c7b9 128static int cifs_debug_data_proc_show(struct seq_file *m, void *v)
1da177e4 129{
f1987b44 130 struct list_head *tmp1, *tmp2, *tmp3;
ffdd6e4d 131 struct mid_q_entry *mid_entry;
14fbf50d 132 struct TCP_Server_Info *server;
96daf2b0
SF
133 struct cifs_ses *ses;
134 struct cifs_tcon *tcon;
f1987b44
JL
135 int i, j;
136 __u32 dev_type;
1da177e4 137
f984c7b9 138 seq_puts(m,
1da177e4
LT
139 "Display Internal CIFS Data Structures for Debugging\n"
140 "---------------------------------------------------\n");
f984c7b9 141 seq_printf(m, "CIFS Version %s\n", CIFS_VERSION);
ca40b714 142 seq_printf(m, "Features:");
f579903e 143#ifdef CONFIG_CIFS_DFS_UPCALL
ca40b714 144 seq_printf(m, " dfs");
f579903e
SJ
145#endif
146#ifdef CONFIG_CIFS_FSCACHE
ca40b714 147 seq_printf(m, " fscache");
f579903e
SJ
148#endif
149#ifdef CONFIG_CIFS_WEAK_PW_HASH
ca40b714 150 seq_printf(m, " lanman");
f579903e
SJ
151#endif
152#ifdef CONFIG_CIFS_POSIX
ca40b714 153 seq_printf(m, " posix");
f579903e
SJ
154#endif
155#ifdef CONFIG_CIFS_UPCALL
ca40b714 156 seq_printf(m, " spnego");
f579903e
SJ
157#endif
158#ifdef CONFIG_CIFS_XATTR
ca40b714
JL
159 seq_printf(m, " xattr");
160#endif
161#ifdef CONFIG_CIFS_ACL
162 seq_printf(m, " acl");
f579903e
SJ
163#endif
164 seq_putc(m, '\n');
f984c7b9
AD
165 seq_printf(m, "Active VFS Requests: %d\n", GlobalTotalActiveXid);
166 seq_printf(m, "Servers:");
1da177e4
LT
167
168 i = 0;
3f9bcca7 169 spin_lock(&cifs_tcp_ses_lock);
f1987b44
JL
170 list_for_each(tmp1, &cifs_tcp_ses_list) {
171 server = list_entry(tmp1, struct TCP_Server_Info,
14fbf50d 172 tcp_ses_list);
1da177e4 173 i++;
14fbf50d 174 list_for_each(tmp2, &server->smb_ses_list) {
96daf2b0 175 ses = list_entry(tmp2, struct cifs_ses,
14fbf50d
JL
176 smb_ses_list);
177 if ((ses->serverDomain == NULL) ||
178 (ses->serverOS == NULL) ||
179 (ses->serverNOS == NULL)) {
f1987b44
JL
180 seq_printf(m, "\n%d) entry for %s not fully "
181 "displayed\n\t", i, ses->serverName);
14fbf50d
JL
182 } else {
183 seq_printf(m,
f1987b44
JL
184 "\n%d) Name: %s Domain: %s Uses: %d OS:"
185 " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
221601c3 186 " session status: %d\t",
b8643e1b 187 i, ses->serverName, ses->serverDomain,
14fbf50d 188 ses->ses_count, ses->serverOS, ses->serverNOS,
221601c3 189 ses->capabilities, ses->status);
14fbf50d 190 }
f984c7b9 191 seq_printf(m, "TCP status: %d\n\tLocal Users To "
14fbf50d
JL
192 "Server: %d SecMode: 0x%x Req On Wire: %d",
193 server->tcpStatus, server->srv_count,
fc40f9cf 194 server->sec_mode, in_flight(server));
131afd0b
SF
195
196#ifdef CONFIG_CIFS_STATS2
f984c7b9 197 seq_printf(m, " In Send: %d In MaxReq Wait: %d",
789e6661 198 atomic_read(&server->in_send),
14fbf50d 199 atomic_read(&server->num_waiters));
131afd0b
SF
200#endif
201
f1987b44
JL
202 seq_puts(m, "\n\tShares:");
203 j = 0;
204 list_for_each(tmp3, &ses->tcon_list) {
96daf2b0 205 tcon = list_entry(tmp3, struct cifs_tcon,
f1987b44
JL
206 tcon_list);
207 ++j;
208 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
209 seq_printf(m, "\n\t%d) %s Mounts: %d ", j,
210 tcon->treeName, tcon->tc_count);
211 if (tcon->nativeFileSystem) {
212 seq_printf(m, "Type: %s ",
213 tcon->nativeFileSystem);
214 }
215 seq_printf(m, "DevInfo: 0x%x Attributes: 0x%x"
216 "\nPathComponentMax: %d Status: 0x%d",
217 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
218 le32_to_cpu(tcon->fsAttrInfo.Attributes),
219 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
220 tcon->tidStatus);
221 if (dev_type == FILE_DEVICE_DISK)
222 seq_puts(m, " type: DISK ");
223 else if (dev_type == FILE_DEVICE_CD_ROM)
224 seq_puts(m, " type: CDROM ");
225 else
226 seq_printf(m, " type: %d ", dev_type);
227
228 if (tcon->need_reconnect)
229 seq_puts(m, "\tDISCONNECTED ");
230 seq_putc(m, '\n');
231 }
232
233 seq_puts(m, "\n\tMIDs:\n");
1da177e4
LT
234
235 spin_lock(&GlobalMid_Lock);
14fbf50d 236 list_for_each(tmp3, &server->pending_mid_q) {
f1987b44 237 mid_entry = list_entry(tmp3, struct mid_q_entry,
1da177e4 238 qhead);
f1987b44 239 seq_printf(m, "\tState: %d com: %d pid:"
7c9421e1
PS
240 " %d cbdata: %p mid %llu\n",
241 mid_entry->mid_state,
242 le16_to_cpu(mid_entry->command),
243 mid_entry->pid,
244 mid_entry->callback_data,
245 mid_entry->mid);
1da177e4 246 }
221601c3 247 spin_unlock(&GlobalMid_Lock);
1da177e4 248 }
1da177e4 249 }
3f9bcca7 250 spin_unlock(&cifs_tcp_ses_lock);
f984c7b9 251 seq_putc(m, '\n');
1da177e4 252
1da177e4 253 /* BB add code to dump additional info such as TCP session info now */
f984c7b9
AD
254 return 0;
255}
1da177e4 256
f984c7b9
AD
257static int cifs_debug_data_proc_open(struct inode *inode, struct file *file)
258{
259 return single_open(file, cifs_debug_data_proc_show, NULL);
1da177e4
LT
260}
261
f984c7b9
AD
262static const struct file_operations cifs_debug_data_proc_fops = {
263 .owner = THIS_MODULE,
264 .open = cifs_debug_data_proc_open,
265 .read = seq_read,
266 .llseek = seq_lseek,
267 .release = single_release,
268};
1047abc1 269
f984c7b9
AD
270#ifdef CONFIG_CIFS_STATS
271static ssize_t cifs_stats_proc_write(struct file *file,
272 const char __user *buffer, size_t count, loff_t *ppos)
1047abc1 273{
221601c3
SF
274 char c;
275 int rc;
f1987b44
JL
276 struct list_head *tmp1, *tmp2, *tmp3;
277 struct TCP_Server_Info *server;
96daf2b0
SF
278 struct cifs_ses *ses;
279 struct cifs_tcon *tcon;
1047abc1 280
221601c3
SF
281 rc = get_user(c, buffer);
282 if (rc)
283 return rc;
1047abc1 284
221601c3 285 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
4498eed5
SF
286#ifdef CONFIG_CIFS_STATS2
287 atomic_set(&totBufAllocCount, 0);
288 atomic_set(&totSmBufAllocCount, 0);
289#endif /* CONFIG_CIFS_STATS2 */
3f9bcca7 290 spin_lock(&cifs_tcp_ses_lock);
f1987b44
JL
291 list_for_each(tmp1, &cifs_tcp_ses_list) {
292 server = list_entry(tmp1, struct TCP_Server_Info,
293 tcp_ses_list);
c2b3382c 294 list_for_each(tmp2, &server->smb_ses_list) {
96daf2b0 295 ses = list_entry(tmp2, struct cifs_ses,
c2b3382c 296 smb_ses_list);
f1987b44
JL
297 list_for_each(tmp3, &ses->tcon_list) {
298 tcon = list_entry(tmp3,
96daf2b0 299 struct cifs_tcon,
f1987b44
JL
300 tcon_list);
301 atomic_set(&tcon->num_smbs_sent, 0);
44c58186
PS
302 if (server->ops->clear_stats)
303 server->ops->clear_stats(tcon);
f1987b44
JL
304 }
305 }
1047abc1 306 }
3f9bcca7 307 spin_unlock(&cifs_tcp_ses_lock);
1047abc1
SF
308 }
309
221601c3 310 return count;
1047abc1
SF
311}
312
f984c7b9 313static int cifs_stats_proc_show(struct seq_file *m, void *v)
1da177e4 314{
f984c7b9 315 int i;
f1987b44
JL
316 struct list_head *tmp1, *tmp2, *tmp3;
317 struct TCP_Server_Info *server;
96daf2b0
SF
318 struct cifs_ses *ses;
319 struct cifs_tcon *tcon;
1da177e4 320
f984c7b9 321 seq_printf(m,
1da177e4
LT
322 "Resources in use\nCIFS Session: %d\n",
323 sesInfoAllocCount.counter);
f984c7b9 324 seq_printf(m, "Share (unique mount targets): %d\n",
1da177e4 325 tconInfoAllocCount.counter);
f984c7b9 326 seq_printf(m, "SMB Request/Response Buffer: %d Pool size: %d\n",
b8643e1b
SF
327 bufAllocCount.counter,
328 cifs_min_rcv + tcpSesAllocCount.counter);
f984c7b9 329 seq_printf(m, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
221601c3 330 smBufAllocCount.counter, cifs_min_small);
07475ffb 331#ifdef CONFIG_CIFS_STATS2
f984c7b9 332 seq_printf(m, "Total Large %d Small %d Allocations\n",
07475ffb 333 atomic_read(&totBufAllocCount),
221601c3 334 atomic_read(&totSmBufAllocCount));
07475ffb
SF
335#endif /* CONFIG_CIFS_STATS2 */
336
8097531a 337 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
f984c7b9 338 seq_printf(m,
1da177e4 339 "\n%d session %d share reconnects\n",
221601c3 340 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
1da177e4 341
f984c7b9 342 seq_printf(m,
1da177e4 343 "Total vfs operations: %d maximum at one time: %d\n",
221601c3 344 GlobalCurrentXid, GlobalMaxActiveXid);
1da177e4
LT
345
346 i = 0;
3f9bcca7 347 spin_lock(&cifs_tcp_ses_lock);
f1987b44
JL
348 list_for_each(tmp1, &cifs_tcp_ses_list) {
349 server = list_entry(tmp1, struct TCP_Server_Info,
350 tcp_ses_list);
351 list_for_each(tmp2, &server->smb_ses_list) {
96daf2b0 352 ses = list_entry(tmp2, struct cifs_ses,
f1987b44
JL
353 smb_ses_list);
354 list_for_each(tmp3, &ses->tcon_list) {
355 tcon = list_entry(tmp3,
96daf2b0 356 struct cifs_tcon,
f1987b44
JL
357 tcon_list);
358 i++;
359 seq_printf(m, "\n%d) %s", i, tcon->treeName);
360 if (tcon->need_reconnect)
361 seq_puts(m, "\tDISCONNECTED ");
44c58186
PS
362 seq_printf(m, "\nSMBs: %d",
363 atomic_read(&tcon->num_smbs_sent));
364 if (server->ops->print_stats)
365 server->ops->print_stats(m, tcon);
f1987b44
JL
366 }
367 }
1da177e4 368 }
3f9bcca7 369 spin_unlock(&cifs_tcp_ses_lock);
1da177e4 370
f984c7b9
AD
371 seq_putc(m, '\n');
372 return 0;
373}
221601c3 374
f984c7b9
AD
375static int cifs_stats_proc_open(struct inode *inode, struct file *file)
376{
377 return single_open(file, cifs_stats_proc_show, NULL);
1da177e4 378}
f984c7b9
AD
379
380static const struct file_operations cifs_stats_proc_fops = {
381 .owner = THIS_MODULE,
382 .open = cifs_stats_proc_open,
383 .read = seq_read,
384 .llseek = seq_lseek,
385 .release = single_release,
386 .write = cifs_stats_proc_write,
387};
90c81e0b 388#endif /* STATS */
1da177e4
LT
389
390static struct proc_dir_entry *proc_fs_cifs;
f984c7b9 391static const struct file_operations cifsFYI_proc_fops;
f984c7b9
AD
392static const struct file_operations cifs_lookup_cache_proc_fops;
393static const struct file_operations traceSMB_proc_fops;
f984c7b9 394static const struct file_operations cifs_security_flags_proc_fops;
f984c7b9 395static const struct file_operations cifs_linux_ext_proc_fops;
1da177e4
LT
396
397void
398cifs_proc_init(void)
399{
36a5aeb8 400 proc_fs_cifs = proc_mkdir("fs/cifs", NULL);
1da177e4
LT
401 if (proc_fs_cifs == NULL)
402 return;
403
f984c7b9 404 proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops);
1da177e4
LT
405
406#ifdef CONFIG_CIFS_STATS
f984c7b9 407 proc_create("Stats", 0, proc_fs_cifs, &cifs_stats_proc_fops);
90c81e0b 408#endif /* STATS */
f984c7b9
AD
409 proc_create("cifsFYI", 0, proc_fs_cifs, &cifsFYI_proc_fops);
410 proc_create("traceSMB", 0, proc_fs_cifs, &traceSMB_proc_fops);
99b1f5b2
SF
411 proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs,
412 &cifs_linux_ext_proc_fops);
99b1f5b2
SF
413 proc_create("SecurityFlags", 0, proc_fs_cifs,
414 &cifs_security_flags_proc_fops);
415 proc_create("LookupCacheEnabled", 0, proc_fs_cifs,
416 &cifs_lookup_cache_proc_fops);
1da177e4
LT
417}
418
419void
420cifs_proc_clean(void)
421{
422 if (proc_fs_cifs == NULL)
423 return;
424
425 remove_proc_entry("DebugData", proc_fs_cifs);
426 remove_proc_entry("cifsFYI", proc_fs_cifs);
427 remove_proc_entry("traceSMB", proc_fs_cifs);
428#ifdef CONFIG_CIFS_STATS
429 remove_proc_entry("Stats", proc_fs_cifs);
430#endif
221601c3 431 remove_proc_entry("SecurityFlags", proc_fs_cifs);
221601c3 432 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
221601c3 433 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
36a5aeb8 434 remove_proc_entry("fs/cifs", NULL);
1da177e4
LT
435}
436
f984c7b9 437static int cifsFYI_proc_show(struct seq_file *m, void *v)
1da177e4 438{
f984c7b9
AD
439 seq_printf(m, "%d\n", cifsFYI);
440 return 0;
441}
1da177e4 442
f984c7b9
AD
443static int cifsFYI_proc_open(struct inode *inode, struct file *file)
444{
445 return single_open(file, cifsFYI_proc_show, NULL);
1da177e4 446}
f984c7b9
AD
447
448static ssize_t cifsFYI_proc_write(struct file *file, const char __user *buffer,
449 size_t count, loff_t *ppos)
1da177e4
LT
450{
451 char c;
452 int rc;
453
454 rc = get_user(c, buffer);
455 if (rc)
456 return rc;
457 if (c == '0' || c == 'n' || c == 'N')
458 cifsFYI = 0;
459 else if (c == '1' || c == 'y' || c == 'Y')
460 cifsFYI = 1;
221601c3 461 else if ((c > '1') && (c <= '9'))
1047abc1 462 cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
1da177e4
LT
463
464 return count;
465}
466
f984c7b9
AD
467static const struct file_operations cifsFYI_proc_fops = {
468 .owner = THIS_MODULE,
469 .open = cifsFYI_proc_open,
470 .read = seq_read,
471 .llseek = seq_lseek,
472 .release = single_release,
473 .write = cifsFYI_proc_write,
474};
1da177e4 475
f984c7b9
AD
476static int cifs_linux_ext_proc_show(struct seq_file *m, void *v)
477{
478 seq_printf(m, "%d\n", linuxExtEnabled);
479 return 0;
480}
1da177e4 481
f984c7b9
AD
482static int cifs_linux_ext_proc_open(struct inode *inode, struct file *file)
483{
484 return single_open(file, cifs_linux_ext_proc_show, NULL);
1da177e4 485}
f984c7b9
AD
486
487static ssize_t cifs_linux_ext_proc_write(struct file *file,
488 const char __user *buffer, size_t count, loff_t *ppos)
1da177e4 489{
221601c3
SF
490 char c;
491 int rc;
492
493 rc = get_user(c, buffer);
494 if (rc)
495 return rc;
496 if (c == '0' || c == 'n' || c == 'N')
497 linuxExtEnabled = 0;
498 else if (c == '1' || c == 'y' || c == 'Y')
499 linuxExtEnabled = 1;
500
501 return count;
1da177e4
LT
502}
503
f984c7b9
AD
504static const struct file_operations cifs_linux_ext_proc_fops = {
505 .owner = THIS_MODULE,
506 .open = cifs_linux_ext_proc_open,
507 .read = seq_read,
508 .llseek = seq_lseek,
509 .release = single_release,
510 .write = cifs_linux_ext_proc_write,
511};
1da177e4 512
f984c7b9 513static int cifs_lookup_cache_proc_show(struct seq_file *m, void *v)
1da177e4 514{
f984c7b9
AD
515 seq_printf(m, "%d\n", lookupCacheEnabled);
516 return 0;
517}
1da177e4 518
f984c7b9
AD
519static int cifs_lookup_cache_proc_open(struct inode *inode, struct file *file)
520{
521 return single_open(file, cifs_lookup_cache_proc_show, NULL);
1da177e4 522}
f984c7b9
AD
523
524static ssize_t cifs_lookup_cache_proc_write(struct file *file,
525 const char __user *buffer, size_t count, loff_t *ppos)
1da177e4
LT
526{
527 char c;
528 int rc;
529
530 rc = get_user(c, buffer);
531 if (rc)
532 return rc;
533 if (c == '0' || c == 'n' || c == 'N')
534 lookupCacheEnabled = 0;
535 else if (c == '1' || c == 'y' || c == 'Y')
536 lookupCacheEnabled = 1;
537
538 return count;
539}
1da177e4 540
f984c7b9
AD
541static 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};
1da177e4 549
f984c7b9
AD
550static int traceSMB_proc_show(struct seq_file *m, void *v)
551{
552 seq_printf(m, "%d\n", traceSMB);
553 return 0;
554}
1da177e4 555
f984c7b9
AD
556static int traceSMB_proc_open(struct inode *inode, struct file *file)
557{
558 return single_open(file, traceSMB_proc_show, NULL);
1da177e4 559}
f984c7b9
AD
560
561static ssize_t traceSMB_proc_write(struct file *file, const char __user *buffer,
562 size_t count, loff_t *ppos)
1da177e4
LT
563{
564 char c;
565 int rc;
566
567 rc = get_user(c, buffer);
568 if (rc)
569 return rc;
570 if (c == '0' || c == 'n' || c == 'N')
571 traceSMB = 0;
572 else if (c == '1' || c == 'y' || c == 'Y')
573 traceSMB = 1;
574
575 return count;
576}
577
f984c7b9
AD
578static const struct file_operations traceSMB_proc_fops = {
579 .owner = THIS_MODULE,
580 .open = traceSMB_proc_open,
581 .read = seq_read,
582 .llseek = seq_lseek,
583 .release = single_release,
584 .write = traceSMB_proc_write,
585};
1da177e4 586
f984c7b9
AD
587static int cifs_security_flags_proc_show(struct seq_file *m, void *v)
588{
04912d6a 589 seq_printf(m, "0x%x\n", global_secflags);
f984c7b9
AD
590 return 0;
591}
1da177e4 592
f984c7b9
AD
593static int cifs_security_flags_proc_open(struct inode *inode, struct file *file)
594{
595 return single_open(file, cifs_security_flags_proc_show, NULL);
1da177e4 596}
f984c7b9
AD
597
598static ssize_t cifs_security_flags_proc_write(struct file *file,
599 const char __user *buffer, size_t count, loff_t *ppos)
1da177e4 600{
bdc4bf6e
SF
601 unsigned int flags;
602 char flags_string[12];
1da177e4 603 char c;
bdc4bf6e 604
221601c3 605 if ((count < 1) || (count > 11))
3979877e 606 return -EINVAL;
1da177e4 607
bdc4bf6e 608 memset(flags_string, 0, 12);
3979877e 609
221601c3 610 if (copy_from_user(flags_string, buffer, count))
bdc4bf6e 611 return -EFAULT;
3979877e 612
221601c3 613 if (count < 3) {
bdc4bf6e
SF
614 /* single char or single char followed by null */
615 c = flags_string[0];
a013689d 616 if (c == '0' || c == 'n' || c == 'N') {
04912d6a 617 global_secflags = CIFSSEC_DEF; /* default */
a013689d
SF
618 return count;
619 } else if (c == '1' || c == 'y' || c == 'Y') {
04912d6a 620 global_secflags = CIFSSEC_MAX;
a013689d
SF
621 return count;
622 } else if (!isdigit(c)) {
f96637be 623 cifs_dbg(VFS, "invalid flag %c\n", c);
a013689d
SF
624 return -EINVAL;
625 }
bdc4bf6e
SF
626 }
627 /* else we have a number */
628
629 flags = simple_strtoul(flags_string, NULL, 0);
630
f96637be 631 cifs_dbg(FYI, "sec flags 0x%x\n", flags);
bdc4bf6e 632
221601c3 633 if (flags <= 0) {
f96637be 634 cifs_dbg(VFS, "invalid security flags %s\n", flags_string);
bdc4bf6e
SF
635 return -EINVAL;
636 }
1da177e4 637
221601c3 638 if (flags & ~CIFSSEC_MASK) {
f96637be
JP
639 cifs_dbg(VFS, "attempt to set unsupported security flags 0x%x\n",
640 flags & ~CIFSSEC_MASK);
bdc4bf6e
SF
641 return -EINVAL;
642 }
643 /* flags look ok - update the global security flags for cifs module */
04912d6a
JL
644 global_secflags = flags;
645 if (global_secflags & CIFSSEC_MUST_SIGN) {
762e5ab7 646 /* requiring signing implies signing is allowed */
04912d6a 647 global_secflags |= CIFSSEC_MAY_SIGN;
f96637be 648 cifs_dbg(FYI, "packet signing now required\n");
04912d6a 649 } else if ((global_secflags & CIFSSEC_MAY_SIGN) == 0) {
f96637be 650 cifs_dbg(FYI, "packet signing disabled\n");
762e5ab7
SF
651 }
652 /* BB should we turn on MAY flags for other MUST options? */
1da177e4
LT
653 return count;
654}
f984c7b9
AD
655
656static const struct file_operations cifs_security_flags_proc_fops = {
657 .owner = THIS_MODULE,
658 .open = cifs_security_flags_proc_open,
659 .read = seq_read,
660 .llseek = seq_lseek,
661 .release = single_release,
662 .write = cifs_security_flags_proc_write,
663};
90c81e0b 664#else
e086fcea 665inline void cifs_proc_init(void)
90c81e0b
SF
666{
667}
668
e086fcea 669inline void cifs_proc_clean(void)
90c81e0b
SF
670{
671}
672#endif /* PROC_FS */