4 * Copyright (C) International Business Machines Corp., 2000,2005
6 * Modified by Steve French (sfrench@us.ibm.com)
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.
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.
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
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>
30 #include "cifsproto.h"
31 #include "cifs_debug.h"
35 cifs_dump_mem(char *label
, void *data
, int length
)
40 char buf
[10], line
[80];
42 printk(KERN_DEBUG
"%s: dump of %d bytes of data at 0x%p\n",
44 for (i
= 0; i
< length
; i
+= 16) {
46 for (j
= 0; (j
< 4) && (i
+ j
* 4 < length
); j
++) {
47 sprintf(buf
, " %08x", intptr
[i
/ 4 + j
]);
52 for (j
= 0; (j
< 16) && (i
+ j
< length
); j
++) {
53 buf
[1] = isprint(charptr
[i
+ j
]) ? charptr
[i
+ j
] : '.';
56 printk(KERN_DEBUG
"%s\n", line
);
60 #ifdef CONFIG_CIFS_DEBUG
61 void cifs_vfs_err(const char *fmt
, ...)
71 printk(KERN_ERR
"CIFS VFS: %pV", &vaf
);
77 void cifs_dump_detail(void *buf
)
79 #ifdef CONFIG_CIFS_DEBUG2
80 struct smb_hdr
*smb
= (struct smb_hdr
*)buf
;
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
));
86 #endif /* CONFIG_CIFS_DEBUG2 */
89 void cifs_dump_mids(struct TCP_Server_Info
*server
)
91 #ifdef CONFIG_CIFS_DEBUG2
92 struct list_head
*tmp
;
93 struct mid_q_entry
*mid_entry
;
98 cifs_dbg(VFS
, "Dump pending requests:\n");
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
);
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
),
106 mid_entry
->callback_data
,
108 #ifdef CONFIG_CIFS_STATS2
109 cifs_dbg(VFS
, "IsLarge: %d buf: %p time rcv: %ld now: %ld\n",
110 mid_entry
->large_buf
,
112 mid_entry
->when_received
,
115 cifs_dbg(VFS
, "IsMult: %d IsEnd: %d\n",
116 mid_entry
->multiRsp
, mid_entry
->multiEnd
);
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);
123 spin_unlock(&GlobalMid_Lock
);
124 #endif /* CONFIG_CIFS_DEBUG2 */
127 #ifdef CONFIG_PROC_FS
128 static int cifs_debug_data_proc_show(struct seq_file
*m
, void *v
)
130 struct list_head
*tmp1
, *tmp2
, *tmp3
;
131 struct mid_q_entry
*mid_entry
;
132 struct TCP_Server_Info
*server
;
133 struct cifs_ses
*ses
;
134 struct cifs_tcon
*tcon
;
139 "Display Internal CIFS Data Structures for Debugging\n"
140 "---------------------------------------------------\n");
141 seq_printf(m
, "CIFS Version %s\n", CIFS_VERSION
);
142 seq_printf(m
, "Features:");
143 #ifdef CONFIG_CIFS_DFS_UPCALL
144 seq_printf(m
, " dfs");
146 #ifdef CONFIG_CIFS_FSCACHE
147 seq_printf(m
, " fscache");
149 #ifdef CONFIG_CIFS_WEAK_PW_HASH
150 seq_printf(m
, " lanman");
152 #ifdef CONFIG_CIFS_POSIX
153 seq_printf(m
, " posix");
155 #ifdef CONFIG_CIFS_UPCALL
156 seq_printf(m
, " spnego");
158 #ifdef CONFIG_CIFS_XATTR
159 seq_printf(m
, " xattr");
161 #ifdef CONFIG_CIFS_ACL
162 seq_printf(m
, " acl");
165 seq_printf(m
, "Active VFS Requests: %d\n", GlobalTotalActiveXid
);
166 seq_printf(m
, "Servers:");
169 spin_lock(&cifs_tcp_ses_lock
);
170 list_for_each(tmp1
, &cifs_tcp_ses_list
) {
171 server
= list_entry(tmp1
, struct TCP_Server_Info
,
174 list_for_each(tmp2
, &server
->smb_ses_list
) {
175 ses
= list_entry(tmp2
, struct cifs_ses
,
177 if ((ses
->serverDomain
== NULL
) ||
178 (ses
->serverOS
== NULL
) ||
179 (ses
->serverNOS
== NULL
)) {
180 seq_printf(m
, "\n%d) entry for %s not fully "
181 "displayed\n\t", i
, ses
->serverName
);
184 "\n%d) Name: %s Domain: %s Uses: %d OS:"
185 " %s\n\tNOS: %s\tCapability: 0x%x\n\tSMB"
186 " session status: %d\t",
187 i
, ses
->serverName
, ses
->serverDomain
,
188 ses
->ses_count
, ses
->serverOS
, ses
->serverNOS
,
189 ses
->capabilities
, ses
->status
);
191 seq_printf(m
, "TCP status: %d\n\tLocal Users To "
192 "Server: %d SecMode: 0x%x Req On Wire: %d",
193 server
->tcpStatus
, server
->srv_count
,
194 server
->sec_mode
, in_flight(server
));
196 #ifdef CONFIG_CIFS_STATS2
197 seq_printf(m
, " In Send: %d In MaxReq Wait: %d",
198 atomic_read(&server
->in_send
),
199 atomic_read(&server
->num_waiters
));
202 seq_puts(m
, "\n\tShares:");
204 list_for_each(tmp3
, &ses
->tcon_list
) {
205 tcon
= list_entry(tmp3
, struct cifs_tcon
,
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
);
215 seq_printf(m
, "DevInfo: 0x%x Attributes: 0x%x"
216 "\n\tPathComponentMax: %d Status: %d",
217 le32_to_cpu(tcon
->fsDevInfo
.DeviceCharacteristics
),
218 le32_to_cpu(tcon
->fsAttrInfo
.Attributes
),
219 le32_to_cpu(tcon
->fsAttrInfo
.MaxPathNameComponentLength
),
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 ");
226 seq_printf(m
, " type: %d ", dev_type
);
227 if (server
->ops
->dump_share_caps
)
228 server
->ops
->dump_share_caps(m
, tcon
);
230 if (tcon
->need_reconnect
)
231 seq_puts(m
, "\tDISCONNECTED ");
235 seq_puts(m
, "\n\tMIDs:\n");
237 spin_lock(&GlobalMid_Lock
);
238 list_for_each(tmp3
, &server
->pending_mid_q
) {
239 mid_entry
= list_entry(tmp3
, struct mid_q_entry
,
241 seq_printf(m
, "\tState: %d com: %d pid:"
242 " %d cbdata: %p mid %llu\n",
243 mid_entry
->mid_state
,
244 le16_to_cpu(mid_entry
->command
),
246 mid_entry
->callback_data
,
249 spin_unlock(&GlobalMid_Lock
);
252 spin_unlock(&cifs_tcp_ses_lock
);
255 /* BB add code to dump additional info such as TCP session info now */
259 static int cifs_debug_data_proc_open(struct inode
*inode
, struct file
*file
)
261 return single_open(file
, cifs_debug_data_proc_show
, NULL
);
264 static const struct file_operations cifs_debug_data_proc_fops
= {
265 .owner
= THIS_MODULE
,
266 .open
= cifs_debug_data_proc_open
,
269 .release
= single_release
,
272 #ifdef CONFIG_CIFS_STATS
273 static ssize_t
cifs_stats_proc_write(struct file
*file
,
274 const char __user
*buffer
, size_t count
, loff_t
*ppos
)
278 struct list_head
*tmp1
, *tmp2
, *tmp3
;
279 struct TCP_Server_Info
*server
;
280 struct cifs_ses
*ses
;
281 struct cifs_tcon
*tcon
;
283 rc
= get_user(c
, buffer
);
287 if (c
== '1' || c
== 'y' || c
== 'Y' || c
== '0') {
288 #ifdef CONFIG_CIFS_STATS2
289 atomic_set(&totBufAllocCount
, 0);
290 atomic_set(&totSmBufAllocCount
, 0);
291 #endif /* CONFIG_CIFS_STATS2 */
292 spin_lock(&cifs_tcp_ses_lock
);
293 list_for_each(tmp1
, &cifs_tcp_ses_list
) {
294 server
= list_entry(tmp1
, struct TCP_Server_Info
,
296 list_for_each(tmp2
, &server
->smb_ses_list
) {
297 ses
= list_entry(tmp2
, struct cifs_ses
,
299 list_for_each(tmp3
, &ses
->tcon_list
) {
300 tcon
= list_entry(tmp3
,
303 atomic_set(&tcon
->num_smbs_sent
, 0);
304 if (server
->ops
->clear_stats
)
305 server
->ops
->clear_stats(tcon
);
309 spin_unlock(&cifs_tcp_ses_lock
);
315 static int cifs_stats_proc_show(struct seq_file
*m
, void *v
)
318 struct list_head
*tmp1
, *tmp2
, *tmp3
;
319 struct TCP_Server_Info
*server
;
320 struct cifs_ses
*ses
;
321 struct cifs_tcon
*tcon
;
324 "Resources in use\nCIFS Session: %d\n",
325 sesInfoAllocCount
.counter
);
326 seq_printf(m
, "Share (unique mount targets): %d\n",
327 tconInfoAllocCount
.counter
);
328 seq_printf(m
, "SMB Request/Response Buffer: %d Pool size: %d\n",
329 bufAllocCount
.counter
,
330 cifs_min_rcv
+ tcpSesAllocCount
.counter
);
331 seq_printf(m
, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
332 smBufAllocCount
.counter
, cifs_min_small
);
333 #ifdef CONFIG_CIFS_STATS2
334 seq_printf(m
, "Total Large %d Small %d Allocations\n",
335 atomic_read(&totBufAllocCount
),
336 atomic_read(&totSmBufAllocCount
));
337 #endif /* CONFIG_CIFS_STATS2 */
339 seq_printf(m
, "Operations (MIDs): %d\n", atomic_read(&midCount
));
341 "\n%d session %d share reconnects\n",
342 tcpSesReconnectCount
.counter
, tconInfoReconnectCount
.counter
);
345 "Total vfs operations: %d maximum at one time: %d\n",
346 GlobalCurrentXid
, GlobalMaxActiveXid
);
349 spin_lock(&cifs_tcp_ses_lock
);
350 list_for_each(tmp1
, &cifs_tcp_ses_list
) {
351 server
= list_entry(tmp1
, struct TCP_Server_Info
,
353 list_for_each(tmp2
, &server
->smb_ses_list
) {
354 ses
= list_entry(tmp2
, struct cifs_ses
,
356 list_for_each(tmp3
, &ses
->tcon_list
) {
357 tcon
= list_entry(tmp3
,
361 seq_printf(m
, "\n%d) %s", i
, tcon
->treeName
);
362 if (tcon
->need_reconnect
)
363 seq_puts(m
, "\tDISCONNECTED ");
364 seq_printf(m
, "\nSMBs: %d",
365 atomic_read(&tcon
->num_smbs_sent
));
366 if (server
->ops
->print_stats
)
367 server
->ops
->print_stats(m
, tcon
);
371 spin_unlock(&cifs_tcp_ses_lock
);
377 static int cifs_stats_proc_open(struct inode
*inode
, struct file
*file
)
379 return single_open(file
, cifs_stats_proc_show
, NULL
);
382 static const struct file_operations cifs_stats_proc_fops
= {
383 .owner
= THIS_MODULE
,
384 .open
= cifs_stats_proc_open
,
387 .release
= single_release
,
388 .write
= cifs_stats_proc_write
,
392 static struct proc_dir_entry
*proc_fs_cifs
;
393 static const struct file_operations cifsFYI_proc_fops
;
394 static const struct file_operations cifs_lookup_cache_proc_fops
;
395 static const struct file_operations traceSMB_proc_fops
;
396 static const struct file_operations cifs_security_flags_proc_fops
;
397 static const struct file_operations cifs_linux_ext_proc_fops
;
402 proc_fs_cifs
= proc_mkdir("fs/cifs", NULL
);
403 if (proc_fs_cifs
== NULL
)
406 proc_create("DebugData", 0, proc_fs_cifs
, &cifs_debug_data_proc_fops
);
408 #ifdef CONFIG_CIFS_STATS
409 proc_create("Stats", 0, proc_fs_cifs
, &cifs_stats_proc_fops
);
411 proc_create("cifsFYI", 0, proc_fs_cifs
, &cifsFYI_proc_fops
);
412 proc_create("traceSMB", 0, proc_fs_cifs
, &traceSMB_proc_fops
);
413 proc_create("LinuxExtensionsEnabled", 0, proc_fs_cifs
,
414 &cifs_linux_ext_proc_fops
);
415 proc_create("SecurityFlags", 0, proc_fs_cifs
,
416 &cifs_security_flags_proc_fops
);
417 proc_create("LookupCacheEnabled", 0, proc_fs_cifs
,
418 &cifs_lookup_cache_proc_fops
);
422 cifs_proc_clean(void)
424 if (proc_fs_cifs
== NULL
)
427 remove_proc_entry("DebugData", proc_fs_cifs
);
428 remove_proc_entry("cifsFYI", proc_fs_cifs
);
429 remove_proc_entry("traceSMB", proc_fs_cifs
);
430 #ifdef CONFIG_CIFS_STATS
431 remove_proc_entry("Stats", proc_fs_cifs
);
433 remove_proc_entry("SecurityFlags", proc_fs_cifs
);
434 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs
);
435 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs
);
436 remove_proc_entry("fs/cifs", NULL
);
439 static int cifsFYI_proc_show(struct seq_file
*m
, void *v
)
441 seq_printf(m
, "%d\n", cifsFYI
);
445 static int cifsFYI_proc_open(struct inode
*inode
, struct file
*file
)
447 return single_open(file
, cifsFYI_proc_show
, NULL
);
450 static ssize_t
cifsFYI_proc_write(struct file
*file
, const char __user
*buffer
,
451 size_t count
, loff_t
*ppos
)
456 rc
= get_user(c
, buffer
);
459 if (c
== '0' || c
== 'n' || c
== 'N')
461 else if (c
== '1' || c
== 'y' || c
== 'Y')
463 else if ((c
> '1') && (c
<= '9'))
464 cifsFYI
= (int) (c
- '0'); /* see cifs_debug.h for meanings */
469 static const struct file_operations cifsFYI_proc_fops
= {
470 .owner
= THIS_MODULE
,
471 .open
= cifsFYI_proc_open
,
474 .release
= single_release
,
475 .write
= cifsFYI_proc_write
,
478 static int cifs_linux_ext_proc_show(struct seq_file
*m
, void *v
)
480 seq_printf(m
, "%d\n", linuxExtEnabled
);
484 static int cifs_linux_ext_proc_open(struct inode
*inode
, struct file
*file
)
486 return single_open(file
, cifs_linux_ext_proc_show
, NULL
);
489 static ssize_t
cifs_linux_ext_proc_write(struct file
*file
,
490 const char __user
*buffer
, size_t count
, loff_t
*ppos
)
495 rc
= get_user(c
, buffer
);
498 if (c
== '0' || c
== 'n' || c
== 'N')
500 else if (c
== '1' || c
== 'y' || c
== 'Y')
506 static const struct file_operations cifs_linux_ext_proc_fops
= {
507 .owner
= THIS_MODULE
,
508 .open
= cifs_linux_ext_proc_open
,
511 .release
= single_release
,
512 .write
= cifs_linux_ext_proc_write
,
515 static int cifs_lookup_cache_proc_show(struct seq_file
*m
, void *v
)
517 seq_printf(m
, "%d\n", lookupCacheEnabled
);
521 static int cifs_lookup_cache_proc_open(struct inode
*inode
, struct file
*file
)
523 return single_open(file
, cifs_lookup_cache_proc_show
, NULL
);
526 static ssize_t
cifs_lookup_cache_proc_write(struct file
*file
,
527 const char __user
*buffer
, size_t count
, loff_t
*ppos
)
532 rc
= get_user(c
, buffer
);
535 if (c
== '0' || c
== 'n' || c
== 'N')
536 lookupCacheEnabled
= 0;
537 else if (c
== '1' || c
== 'y' || c
== 'Y')
538 lookupCacheEnabled
= 1;
543 static const struct file_operations cifs_lookup_cache_proc_fops
= {
544 .owner
= THIS_MODULE
,
545 .open
= cifs_lookup_cache_proc_open
,
548 .release
= single_release
,
549 .write
= cifs_lookup_cache_proc_write
,
552 static int traceSMB_proc_show(struct seq_file
*m
, void *v
)
554 seq_printf(m
, "%d\n", traceSMB
);
558 static int traceSMB_proc_open(struct inode
*inode
, struct file
*file
)
560 return single_open(file
, traceSMB_proc_show
, NULL
);
563 static ssize_t
traceSMB_proc_write(struct file
*file
, const char __user
*buffer
,
564 size_t count
, loff_t
*ppos
)
569 rc
= get_user(c
, buffer
);
572 if (c
== '0' || c
== 'n' || c
== 'N')
574 else if (c
== '1' || c
== 'y' || c
== 'Y')
580 static const struct file_operations traceSMB_proc_fops
= {
581 .owner
= THIS_MODULE
,
582 .open
= traceSMB_proc_open
,
585 .release
= single_release
,
586 .write
= traceSMB_proc_write
,
589 static int cifs_security_flags_proc_show(struct seq_file
*m
, void *v
)
591 seq_printf(m
, "0x%x\n", global_secflags
);
595 static int cifs_security_flags_proc_open(struct inode
*inode
, struct file
*file
)
597 return single_open(file
, cifs_security_flags_proc_show
, NULL
);
601 * Ensure that if someone sets a MUST flag, that we disable all other MAY
602 * flags except for the ones corresponding to the given MUST flag. If there are
603 * multiple MUST flags, then try to prefer more secure ones.
606 cifs_security_flags_handle_must_flags(unsigned int *flags
)
608 unsigned int signflags
= *flags
& CIFSSEC_MUST_SIGN
;
610 if ((*flags
& CIFSSEC_MUST_KRB5
) == CIFSSEC_MUST_KRB5
)
611 *flags
= CIFSSEC_MUST_KRB5
;
612 else if ((*flags
& CIFSSEC_MUST_NTLMSSP
) == CIFSSEC_MUST_NTLMSSP
)
613 *flags
= CIFSSEC_MUST_NTLMSSP
;
614 else if ((*flags
& CIFSSEC_MUST_NTLMV2
) == CIFSSEC_MUST_NTLMV2
)
615 *flags
= CIFSSEC_MUST_NTLMV2
;
616 else if ((*flags
& CIFSSEC_MUST_NTLM
) == CIFSSEC_MUST_NTLM
)
617 *flags
= CIFSSEC_MUST_NTLM
;
618 else if ((*flags
& CIFSSEC_MUST_LANMAN
) == CIFSSEC_MUST_LANMAN
)
619 *flags
= CIFSSEC_MUST_LANMAN
;
620 else if ((*flags
& CIFSSEC_MUST_PLNTXT
) == CIFSSEC_MUST_PLNTXT
)
621 *flags
= CIFSSEC_MUST_PLNTXT
;
626 static ssize_t
cifs_security_flags_proc_write(struct file
*file
,
627 const char __user
*buffer
, size_t count
, loff_t
*ppos
)
631 char flags_string
[12];
634 if ((count
< 1) || (count
> 11))
637 memset(flags_string
, 0, 12);
639 if (copy_from_user(flags_string
, buffer
, count
))
643 /* single char or single char followed by null */
645 if (c
== '0' || c
== 'n' || c
== 'N') {
646 global_secflags
= CIFSSEC_DEF
; /* default */
648 } else if (c
== '1' || c
== 'y' || c
== 'Y') {
649 global_secflags
= CIFSSEC_MAX
;
651 } else if (!isdigit(c
)) {
652 cifs_dbg(VFS
, "Invalid SecurityFlags: %s\n",
658 /* else we have a number */
659 rc
= kstrtouint(flags_string
, 0, &flags
);
661 cifs_dbg(VFS
, "Invalid SecurityFlags: %s\n",
666 cifs_dbg(FYI
, "sec flags 0x%x\n", flags
);
669 cifs_dbg(VFS
, "Invalid SecurityFlags: %s\n", flags_string
);
673 if (flags
& ~CIFSSEC_MASK
) {
674 cifs_dbg(VFS
, "Unsupported security flags: 0x%x\n",
675 flags
& ~CIFSSEC_MASK
);
679 cifs_security_flags_handle_must_flags(&flags
);
681 /* flags look ok - update the global security flags for cifs module */
682 global_secflags
= flags
;
683 if (global_secflags
& CIFSSEC_MUST_SIGN
) {
684 /* requiring signing implies signing is allowed */
685 global_secflags
|= CIFSSEC_MAY_SIGN
;
686 cifs_dbg(FYI
, "packet signing now required\n");
687 } else if ((global_secflags
& CIFSSEC_MAY_SIGN
) == 0) {
688 cifs_dbg(FYI
, "packet signing disabled\n");
690 /* BB should we turn on MAY flags for other MUST options? */
694 static const struct file_operations cifs_security_flags_proc_fops
= {
695 .owner
= THIS_MODULE
,
696 .open
= cifs_security_flags_proc_open
,
699 .release
= single_release
,
700 .write
= cifs_security_flags_proc_write
,
703 inline void cifs_proc_init(void)
707 inline void cifs_proc_clean(void)