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_DEBUG2
61 void cifs_dump_detail(struct smb_hdr
*smb
)
63 cERROR(1, ("Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d",
64 smb
->Command
, smb
->Status
.CifsError
,
65 smb
->Flags
, smb
->Flags2
, smb
->Mid
, smb
->Pid
));
66 cERROR(1, ("smb buf %p len %d", smb
, smbCalcSize_LE(smb
)));
70 void cifs_dump_mids(struct TCP_Server_Info
*server
)
72 struct list_head
*tmp
;
73 struct mid_q_entry
*mid_entry
;
78 cERROR(1, ("Dump pending requests:"));
79 spin_lock(&GlobalMid_Lock
);
80 list_for_each(tmp
, &server
->pending_mid_q
) {
81 mid_entry
= list_entry(tmp
, struct mid_q_entry
, qhead
);
83 cERROR(1, ("State: %d Cmd: %d Pid: %d Tsk: %p Mid %d",
85 (int)mid_entry
->command
,
89 #ifdef CONFIG_CIFS_STATS2
90 cERROR(1, ("IsLarge: %d buf: %p time rcv: %ld now: %ld",
93 mid_entry
->when_received
,
96 cERROR(1, ("IsMult: %d IsEnd: %d", mid_entry
->multiRsp
,
97 mid_entry
->multiEnd
));
98 if (mid_entry
->resp_buf
) {
99 cifs_dump_detail(mid_entry
->resp_buf
);
100 cifs_dump_mem("existing buf: ",
106 spin_unlock(&GlobalMid_Lock
);
108 #endif /* CONFIG_CIFS_DEBUG2 */
110 #ifdef CONFIG_PROC_FS
112 cifs_debug_data_read(char *buf
, char **beginBuffer
, off_t offset
,
113 int count
, int *eof
, void *data
)
115 struct list_head
*tmp
;
116 struct list_head
*tmp1
;
117 struct mid_q_entry
*mid_entry
;
118 struct cifsSesInfo
*ses
;
119 struct cifsTconInfo
*tcon
;
122 char *original_buf
= buf
;
124 *beginBuffer
= buf
+ offset
;
128 "Display Internal CIFS Data Structures for Debugging\n"
129 "---------------------------------------------------\n");
131 length
= sprintf(buf
, "CIFS Version %s\n", CIFS_VERSION
);
133 length
= sprintf(buf
,
134 "Active VFS Requests: %d\n", GlobalTotalActiveXid
);
136 length
= sprintf(buf
, "Servers:");
140 read_lock(&GlobalSMBSeslock
);
141 list_for_each(tmp
, &GlobalSMBSessionList
) {
143 ses
= list_entry(tmp
, struct cifsSesInfo
, cifsSessionList
);
144 if ((ses
->serverDomain
== NULL
) || (ses
->serverOS
== NULL
) ||
145 (ses
->serverNOS
== NULL
)) {
146 buf
+= sprintf(buf
, "\nentry for %s not fully "
147 "displayed\n\t", ses
->serverName
);
151 "\n%d) Name: %s Domain: %s Mounts: %d OS:"
152 " %s \n\tNOS: %s\tCapability: 0x%x\n\tSMB"
153 " session status: %d\t",
154 i
, ses
->serverName
, ses
->serverDomain
,
155 atomic_read(&ses
->inUse
),
156 ses
->serverOS
, ses
->serverNOS
,
157 ses
->capabilities
, ses
->status
);
161 buf
+= sprintf(buf
, "TCP status: %d\n\tLocal Users To "
162 "Server: %d SecMode: 0x%x Req On Wire: %d",
163 ses
->server
->tcpStatus
,
164 atomic_read(&ses
->server
->socketUseCount
),
165 ses
->server
->secMode
,
166 atomic_read(&ses
->server
->inFlight
));
168 #ifdef CONFIG_CIFS_STATS2
169 buf
+= sprintf(buf
, " In Send: %d In MaxReq Wait: %d",
170 atomic_read(&ses
->server
->inSend
),
171 atomic_read(&ses
->server
->num_waiters
));
174 length
= sprintf(buf
, "\nMIDs:\n");
177 spin_lock(&GlobalMid_Lock
);
178 list_for_each(tmp1
, &ses
->server
->pending_mid_q
) {
179 mid_entry
= list_entry(tmp1
, struct
183 length
= sprintf(buf
,
184 "State: %d com: %d pid:"
185 " %d tsk: %p mid %d\n",
187 (int)mid_entry
->command
,
194 spin_unlock(&GlobalMid_Lock
);
198 read_unlock(&GlobalSMBSeslock
);
202 length
= sprintf(buf
, "Shares:");
206 read_lock(&GlobalSMBSeslock
);
207 list_for_each(tmp
, &GlobalTreeConnectionList
) {
210 tcon
= list_entry(tmp
, struct cifsTconInfo
, cifsConnectionList
);
211 dev_type
= le32_to_cpu(tcon
->fsDevInfo
.DeviceType
);
214 "\n%d) %s Uses: %d Type: %s DevInfo: 0x%x "
215 "Attributes: 0x%x\nPathComponentMax: %d Status: %d",
217 atomic_read(&tcon
->useCount
),
218 tcon
->nativeFileSystem
,
219 le32_to_cpu(tcon
->fsDevInfo
.DeviceCharacteristics
),
220 le32_to_cpu(tcon
->fsAttrInfo
.Attributes
),
221 le32_to_cpu(tcon
->fsAttrInfo
.MaxPathNameComponentLength
),
224 if (dev_type
== FILE_DEVICE_DISK
)
225 length
= sprintf(buf
, " type: DISK ");
226 else if (dev_type
== FILE_DEVICE_CD_ROM
)
227 length
= sprintf(buf
, " type: CDROM ");
230 sprintf(buf
, " type: %d ", dev_type
);
232 if (tcon
->tidStatus
== CifsNeedReconnect
) {
233 buf
+= sprintf(buf
, "\tDISCONNECTED ");
237 read_unlock(&GlobalSMBSeslock
);
239 length
= sprintf(buf
, "\n");
242 /* BB add code to dump additional info such as TCP session info now */
243 /* Now calculate total size of returned data */
244 length
= buf
- original_buf
;
246 if (offset
+ count
>= length
)
248 if (length
< offset
) {
252 length
= length
- offset
;
260 #ifdef CONFIG_CIFS_STATS
263 cifs_stats_write(struct file
*file
, const char __user
*buffer
,
264 unsigned long count
, void *data
)
268 struct list_head
*tmp
;
269 struct cifsTconInfo
*tcon
;
271 rc
= get_user(c
, buffer
);
275 if (c
== '1' || c
== 'y' || c
== 'Y' || c
== '0') {
276 read_lock(&GlobalSMBSeslock
);
277 #ifdef CONFIG_CIFS_STATS2
278 atomic_set(&totBufAllocCount
, 0);
279 atomic_set(&totSmBufAllocCount
, 0);
280 #endif /* CONFIG_CIFS_STATS2 */
281 list_for_each(tmp
, &GlobalTreeConnectionList
) {
282 tcon
= list_entry(tmp
, struct cifsTconInfo
,
284 atomic_set(&tcon
->num_smbs_sent
, 0);
285 atomic_set(&tcon
->num_writes
, 0);
286 atomic_set(&tcon
->num_reads
, 0);
287 atomic_set(&tcon
->num_oplock_brks
, 0);
288 atomic_set(&tcon
->num_opens
, 0);
289 atomic_set(&tcon
->num_closes
, 0);
290 atomic_set(&tcon
->num_deletes
, 0);
291 atomic_set(&tcon
->num_mkdirs
, 0);
292 atomic_set(&tcon
->num_rmdirs
, 0);
293 atomic_set(&tcon
->num_renames
, 0);
294 atomic_set(&tcon
->num_t2renames
, 0);
295 atomic_set(&tcon
->num_ffirst
, 0);
296 atomic_set(&tcon
->num_fnext
, 0);
297 atomic_set(&tcon
->num_fclose
, 0);
298 atomic_set(&tcon
->num_hardlinks
, 0);
299 atomic_set(&tcon
->num_symlinks
, 0);
300 atomic_set(&tcon
->num_locks
, 0);
302 read_unlock(&GlobalSMBSeslock
);
309 cifs_stats_read(char *buf
, char **beginBuffer
, off_t offset
,
310 int count
, int *eof
, void *data
)
312 int item_length
, i
, length
;
313 struct list_head
*tmp
;
314 struct cifsTconInfo
*tcon
;
316 *beginBuffer
= buf
+ offset
;
318 length
= sprintf(buf
,
319 "Resources in use\nCIFS Session: %d\n",
320 sesInfoAllocCount
.counter
);
323 sprintf(buf
, "Share (unique mount targets): %d\n",
324 tconInfoAllocCount
.counter
);
325 length
+= item_length
;
328 sprintf(buf
, "SMB Request/Response Buffer: %d Pool size: %d\n",
329 bufAllocCount
.counter
,
330 cifs_min_rcv
+ tcpSesAllocCount
.counter
);
331 length
+= item_length
;
334 sprintf(buf
, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
335 smBufAllocCount
.counter
, cifs_min_small
);
336 length
+= item_length
;
338 #ifdef CONFIG_CIFS_STATS2
339 item_length
= sprintf(buf
, "Total Large %d Small %d Allocations\n",
340 atomic_read(&totBufAllocCount
),
341 atomic_read(&totSmBufAllocCount
));
342 length
+= item_length
;
344 #endif /* CONFIG_CIFS_STATS2 */
347 sprintf(buf
, "Operations (MIDs): %d\n",
349 length
+= item_length
;
351 item_length
= sprintf(buf
,
352 "\n%d session %d share reconnects\n",
353 tcpSesReconnectCount
.counter
, tconInfoReconnectCount
.counter
);
354 length
+= item_length
;
357 item_length
= sprintf(buf
,
358 "Total vfs operations: %d maximum at one time: %d\n",
359 GlobalCurrentXid
, GlobalMaxActiveXid
);
360 length
+= item_length
;
364 read_lock(&GlobalSMBSeslock
);
365 list_for_each(tmp
, &GlobalTreeConnectionList
) {
367 tcon
= list_entry(tmp
, struct cifsTconInfo
, cifsConnectionList
);
368 item_length
= sprintf(buf
, "\n%d) %s", i
, tcon
->treeName
);
370 length
+= item_length
;
371 if (tcon
->tidStatus
== CifsNeedReconnect
) {
372 buf
+= sprintf(buf
, "\tDISCONNECTED ");
375 item_length
= sprintf(buf
, "\nSMBs: %d Oplock Breaks: %d",
376 atomic_read(&tcon
->num_smbs_sent
),
377 atomic_read(&tcon
->num_oplock_brks
));
379 length
+= item_length
;
380 item_length
= sprintf(buf
, "\nReads: %d Bytes: %lld",
381 atomic_read(&tcon
->num_reads
),
382 (long long)(tcon
->bytes_read
));
384 length
+= item_length
;
385 item_length
= sprintf(buf
, "\nWrites: %d Bytes: %lld",
386 atomic_read(&tcon
->num_writes
),
387 (long long)(tcon
->bytes_written
));
389 length
+= item_length
;
390 item_length
= sprintf(buf
,
391 "\nLocks: %d HardLinks: %d Symlinks: %d",
392 atomic_read(&tcon
->num_locks
),
393 atomic_read(&tcon
->num_hardlinks
),
394 atomic_read(&tcon
->num_symlinks
));
396 length
+= item_length
;
398 item_length
= sprintf(buf
, "\nOpens: %d Closes: %d Deletes: %d",
399 atomic_read(&tcon
->num_opens
),
400 atomic_read(&tcon
->num_closes
),
401 atomic_read(&tcon
->num_deletes
));
403 length
+= item_length
;
404 item_length
= sprintf(buf
, "\nMkdirs: %d Rmdirs: %d",
405 atomic_read(&tcon
->num_mkdirs
),
406 atomic_read(&tcon
->num_rmdirs
));
408 length
+= item_length
;
409 item_length
= sprintf(buf
, "\nRenames: %d T2 Renames %d",
410 atomic_read(&tcon
->num_renames
),
411 atomic_read(&tcon
->num_t2renames
));
413 length
+= item_length
;
414 item_length
= sprintf(buf
, "\nFindFirst: %d FNext %d FClose %d",
415 atomic_read(&tcon
->num_ffirst
),
416 atomic_read(&tcon
->num_fnext
),
417 atomic_read(&tcon
->num_fclose
));
419 length
+= item_length
;
421 read_unlock(&GlobalSMBSeslock
);
423 buf
+= sprintf(buf
, "\n");
426 if (offset
+ count
>= length
)
428 if (length
< offset
) {
432 length
= length
- offset
;
441 static struct proc_dir_entry
*proc_fs_cifs
;
442 read_proc_t cifs_txanchor_read
;
443 static read_proc_t cifsFYI_read
;
444 static write_proc_t cifsFYI_write
;
445 static read_proc_t oplockEnabled_read
;
446 static write_proc_t oplockEnabled_write
;
447 static read_proc_t lookupFlag_read
;
448 static write_proc_t lookupFlag_write
;
449 static read_proc_t traceSMB_read
;
450 static write_proc_t traceSMB_write
;
451 static read_proc_t multiuser_mount_read
;
452 static write_proc_t multiuser_mount_write
;
453 static read_proc_t security_flags_read
;
454 static write_proc_t security_flags_write
;
455 /* static read_proc_t ntlmv2_enabled_read;
456 static write_proc_t ntlmv2_enabled_write;
457 static read_proc_t packet_signing_enabled_read;
458 static write_proc_t packet_signing_enabled_write;*/
459 static read_proc_t experimEnabled_read
;
460 static write_proc_t experimEnabled_write
;
461 static read_proc_t linuxExtensionsEnabled_read
;
462 static write_proc_t linuxExtensionsEnabled_write
;
467 struct proc_dir_entry
*pde
;
469 proc_fs_cifs
= proc_mkdir("cifs", proc_root_fs
);
470 if (proc_fs_cifs
== NULL
)
473 proc_fs_cifs
->owner
= THIS_MODULE
;
474 create_proc_read_entry("DebugData", 0, proc_fs_cifs
,
475 cifs_debug_data_read
, NULL
);
477 #ifdef CONFIG_CIFS_STATS
478 pde
= create_proc_read_entry("Stats", 0, proc_fs_cifs
,
479 cifs_stats_read
, NULL
);
481 pde
->write_proc
= cifs_stats_write
;
483 pde
= create_proc_read_entry("cifsFYI", 0, proc_fs_cifs
,
486 pde
->write_proc
= cifsFYI_write
;
489 create_proc_read_entry("traceSMB", 0, proc_fs_cifs
,
490 traceSMB_read
, NULL
);
492 pde
->write_proc
= traceSMB_write
;
494 pde
= create_proc_read_entry("OplockEnabled", 0, proc_fs_cifs
,
495 oplockEnabled_read
, NULL
);
497 pde
->write_proc
= oplockEnabled_write
;
499 pde
= create_proc_read_entry("Experimental", 0, proc_fs_cifs
,
500 experimEnabled_read
, NULL
);
502 pde
->write_proc
= experimEnabled_write
;
504 pde
= create_proc_read_entry("LinuxExtensionsEnabled", 0, proc_fs_cifs
,
505 linuxExtensionsEnabled_read
, NULL
);
507 pde
->write_proc
= linuxExtensionsEnabled_write
;
510 create_proc_read_entry("MultiuserMount", 0, proc_fs_cifs
,
511 multiuser_mount_read
, NULL
);
513 pde
->write_proc
= multiuser_mount_write
;
516 create_proc_read_entry("SecurityFlags", 0, proc_fs_cifs
,
517 security_flags_read
, NULL
);
519 pde
->write_proc
= security_flags_write
;
522 create_proc_read_entry("LookupCacheEnabled", 0, proc_fs_cifs
,
523 lookupFlag_read
, NULL
);
525 pde
->write_proc
= lookupFlag_write
;
528 create_proc_read_entry("NTLMV2Enabled", 0, proc_fs_cifs,
529 ntlmv2_enabled_read, NULL);
531 pde->write_proc = ntlmv2_enabled_write;
534 create_proc_read_entry("PacketSigningEnabled", 0, proc_fs_cifs,
535 packet_signing_enabled_read, NULL);
537 pde->write_proc = packet_signing_enabled_write;*/
541 cifs_proc_clean(void)
543 if (proc_fs_cifs
== NULL
)
546 remove_proc_entry("DebugData", proc_fs_cifs
);
547 remove_proc_entry("cifsFYI", proc_fs_cifs
);
548 remove_proc_entry("traceSMB", proc_fs_cifs
);
549 #ifdef CONFIG_CIFS_STATS
550 remove_proc_entry("Stats", proc_fs_cifs
);
552 remove_proc_entry("MultiuserMount", proc_fs_cifs
);
553 remove_proc_entry("OplockEnabled", proc_fs_cifs
);
554 /* remove_proc_entry("NTLMV2Enabled",proc_fs_cifs); */
555 remove_proc_entry("SecurityFlags", proc_fs_cifs
);
556 /* remove_proc_entry("PacketSigningEnabled", proc_fs_cifs); */
557 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs
);
558 remove_proc_entry("Experimental", proc_fs_cifs
);
559 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs
);
560 remove_proc_entry("cifs", proc_root_fs
);
564 cifsFYI_read(char *page
, char **start
, off_t off
, int count
,
565 int *eof
, void *data
)
569 len
= sprintf(page
, "%d\n", cifsFYI
);
585 cifsFYI_write(struct file
*file
, const char __user
*buffer
,
586 unsigned long count
, void *data
)
591 rc
= get_user(c
, buffer
);
594 if (c
== '0' || c
== 'n' || c
== 'N')
596 else if (c
== '1' || c
== 'y' || c
== 'Y')
598 else if ((c
> '1') && (c
<= '9'))
599 cifsFYI
= (int) (c
- '0'); /* see cifs_debug.h for meanings */
605 oplockEnabled_read(char *page
, char **start
, off_t off
,
606 int count
, int *eof
, void *data
)
610 len
= sprintf(page
, "%d\n", oplockEnabled
);
626 oplockEnabled_write(struct file
*file
, const char __user
*buffer
,
627 unsigned long count
, void *data
)
632 rc
= get_user(c
, buffer
);
635 if (c
== '0' || c
== 'n' || c
== 'N')
637 else if (c
== '1' || c
== 'y' || c
== 'Y')
644 experimEnabled_read(char *page
, char **start
, off_t off
,
645 int count
, int *eof
, void *data
)
649 len
= sprintf(page
, "%d\n", experimEnabled
);
665 experimEnabled_write(struct file
*file
, const char __user
*buffer
,
666 unsigned long count
, void *data
)
671 rc
= get_user(c
, buffer
);
674 if (c
== '0' || c
== 'n' || c
== 'N')
676 else if (c
== '1' || c
== 'y' || c
== 'Y')
685 linuxExtensionsEnabled_read(char *page
, char **start
, off_t off
,
686 int count
, int *eof
, void *data
)
690 len
= sprintf(page
, "%d\n", linuxExtEnabled
);
705 linuxExtensionsEnabled_write(struct file
*file
, const char __user
*buffer
,
706 unsigned long count
, void *data
)
711 rc
= get_user(c
, buffer
);
714 if (c
== '0' || c
== 'n' || c
== 'N')
716 else if (c
== '1' || c
== 'y' || c
== 'Y')
724 lookupFlag_read(char *page
, char **start
, off_t off
,
725 int count
, int *eof
, void *data
)
729 len
= sprintf(page
, "%d\n", lookupCacheEnabled
);
745 lookupFlag_write(struct file
*file
, const char __user
*buffer
,
746 unsigned long count
, void *data
)
751 rc
= get_user(c
, buffer
);
754 if (c
== '0' || c
== 'n' || c
== 'N')
755 lookupCacheEnabled
= 0;
756 else if (c
== '1' || c
== 'y' || c
== 'Y')
757 lookupCacheEnabled
= 1;
762 traceSMB_read(char *page
, char **start
, off_t off
, int count
,
763 int *eof
, void *data
)
767 len
= sprintf(page
, "%d\n", traceSMB
);
783 traceSMB_write(struct file
*file
, const char __user
*buffer
,
784 unsigned long count
, void *data
)
789 rc
= get_user(c
, buffer
);
792 if (c
== '0' || c
== 'n' || c
== 'N')
794 else if (c
== '1' || c
== 'y' || c
== 'Y')
801 multiuser_mount_read(char *page
, char **start
, off_t off
,
802 int count
, int *eof
, void *data
)
806 len
= sprintf(page
, "%d\n", multiuser_mount
);
822 multiuser_mount_write(struct file
*file
, const char __user
*buffer
,
823 unsigned long count
, void *data
)
828 rc
= get_user(c
, buffer
);
831 if (c
== '0' || c
== 'n' || c
== 'N')
833 else if (c
== '1' || c
== 'y' || c
== 'Y')
840 security_flags_read(char *page
, char **start
, off_t off
,
841 int count
, int *eof
, void *data
)
845 len
= sprintf(page
, "0x%x\n", extended_security
);
861 security_flags_write(struct file
*file
, const char __user
*buffer
,
862 unsigned long count
, void *data
)
865 char flags_string
[12];
868 if ((count
< 1) || (count
> 11))
871 memset(flags_string
, 0, 12);
873 if (copy_from_user(flags_string
, buffer
, count
))
877 /* single char or single char followed by null */
879 if (c
== '0' || c
== 'n' || c
== 'N')
880 extended_security
= CIFSSEC_DEF
; /* default */
881 else if (c
== '1' || c
== 'y' || c
== 'Y')
882 extended_security
= CIFSSEC_MAX
;
885 /* else we have a number */
887 flags
= simple_strtoul(flags_string
, NULL
, 0);
889 cFYI(1, ("sec flags 0x%x", flags
));
892 cERROR(1, ("invalid security flags %s", flags_string
));
896 if (flags
& ~CIFSSEC_MASK
) {
897 cERROR(1, ("attempt to set unsupported security flags 0x%x",
898 flags
& ~CIFSSEC_MASK
));
901 /* flags look ok - update the global security flags for cifs module */
902 extended_security
= flags
;
903 if (extended_security
& CIFSSEC_MUST_SIGN
) {
904 /* requiring signing implies signing is allowed */
905 extended_security
|= CIFSSEC_MAY_SIGN
;
906 cFYI(1, ("packet signing now required"));
907 } else if ((extended_security
& CIFSSEC_MAY_SIGN
) == 0) {
908 cFYI(1, ("packet signing disabled"));
910 /* BB should we turn on MAY flags for other MUST options? */