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: ",
101 mid_entry->resp_buf, 62);
105 spin_unlock(&GlobalMid_Lock);
107 #endif /* CONFIG_CIFS_DEBUG2 */
109 #ifdef CONFIG_PROC_FS
111 cifs_debug_data_read(char *buf, char **beginBuffer, off_t offset,
112 int count, int *eof, void *data)
114 struct list_head *tmp;
115 struct list_head *tmp1;
116 struct mid_q_entry *mid_entry;
117 struct cifsSesInfo *ses;
118 struct cifsTconInfo *tcon;
121 char *original_buf = buf;
123 *beginBuffer = buf + offset;
127 "Display Internal CIFS Data Structures for Debugging\n"
128 "---------------------------------------------------\n");
130 length = sprintf(buf, "CIFS Version %s\n", CIFS_VERSION);
132 length = sprintf(buf,
133 "Active VFS Requests: %d\n", GlobalTotalActiveXid);
135 length = sprintf(buf, "Servers:");
139 read_lock(&GlobalSMBSeslock);
140 list_for_each(tmp, &GlobalSMBSessionList) {
142 ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
143 if ((ses->serverDomain == NULL) || (ses->serverOS == NULL) ||
144 (ses->serverNOS == NULL)) {
145 buf += sprintf(buf, "\nentry for %s not fully "
146 "displayed\n\t", ses->serverName);
150 "\n%d) Name: %s Domain: %s Mounts: %d OS:"
151 " %s \n\tNOS: %s\tCapability: 0x%x\n\tSMB"
152 " session status: %d\t",
153 i, ses->serverName, ses->serverDomain,
154 atomic_read(&ses->inUse),
155 ses->serverOS, ses->serverNOS,
156 ses->capabilities, ses->status);
160 buf += sprintf(buf, "TCP status: %d\n\tLocal Users To "
161 "Server: %d SecMode: 0x%x Req On Wire: %d",
162 ses->server->tcpStatus,
163 atomic_read(&ses->server->socketUseCount),
164 ses->server->secMode,
165 atomic_read(&ses->server->inFlight));
167 #ifdef CONFIG_CIFS_STATS2
168 buf += sprintf(buf, " In Send: %d In MaxReq Wait: %d",
169 atomic_read(&ses->server->inSend),
170 atomic_read(&ses->server->num_waiters));
173 length = sprintf(buf, "\nMIDs:\n");
176 spin_lock(&GlobalMid_Lock);
177 list_for_each(tmp1, &ses->server->pending_mid_q) {
178 mid_entry = list_entry(tmp1, struct
182 length = sprintf(buf,
183 "State: %d com: %d pid:"
184 " %d tsk: %p mid %d\n",
186 (int)mid_entry->command,
193 spin_unlock(&GlobalMid_Lock);
197 read_unlock(&GlobalSMBSeslock);
201 length = sprintf(buf, "Shares:");
205 read_lock(&GlobalSMBSeslock);
206 list_for_each(tmp, &GlobalTreeConnectionList) {
209 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
210 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
211 length = sprintf(buf, "\n%d) %s Uses: %d ", i,
212 tcon->treeName, atomic_read(&tcon->useCount));
214 if (tcon->nativeFileSystem) {
215 length = sprintf(buf, "Type: %s ",
216 tcon->nativeFileSystem);
219 length = sprintf(buf, "DevInfo: 0x%x Attributes: 0x%x"
220 "\nPathComponentMax: %d Status: %d",
221 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
222 le32_to_cpu(tcon->fsAttrInfo.Attributes),
223 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
226 if (dev_type == FILE_DEVICE_DISK)
227 length = sprintf(buf, " type: DISK ");
228 else if (dev_type == FILE_DEVICE_CD_ROM)
229 length = sprintf(buf, " type: CDROM ");
232 sprintf(buf, " type: %d ", dev_type);
234 if (tcon->tidStatus == CifsNeedReconnect) {
235 buf += sprintf(buf, "\tDISCONNECTED ");
239 read_unlock(&GlobalSMBSeslock);
241 length = sprintf(buf, "\n");
244 /* BB add code to dump additional info such as TCP session info now */
245 /* Now calculate total size of returned data */
246 length = buf - original_buf;
248 if (offset + count >= length)
250 if (length < offset) {
254 length = length - offset;
262 #ifdef CONFIG_CIFS_STATS
265 cifs_stats_write(struct file *file, const char __user *buffer,
266 unsigned long count, void *data)
270 struct list_head *tmp;
271 struct cifsTconInfo *tcon;
273 rc = get_user(c, buffer);
277 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
278 read_lock(&GlobalSMBSeslock);
279 #ifdef CONFIG_CIFS_STATS2
280 atomic_set(&totBufAllocCount, 0);
281 atomic_set(&totSmBufAllocCount, 0);
282 #endif /* CONFIG_CIFS_STATS2 */
283 list_for_each(tmp, &GlobalTreeConnectionList) {
284 tcon = list_entry(tmp, struct cifsTconInfo,
286 atomic_set(&tcon->num_smbs_sent, 0);
287 atomic_set(&tcon->num_writes, 0);
288 atomic_set(&tcon->num_reads, 0);
289 atomic_set(&tcon->num_oplock_brks, 0);
290 atomic_set(&tcon->num_opens, 0);
291 atomic_set(&tcon->num_closes, 0);
292 atomic_set(&tcon->num_deletes, 0);
293 atomic_set(&tcon->num_mkdirs, 0);
294 atomic_set(&tcon->num_rmdirs, 0);
295 atomic_set(&tcon->num_renames, 0);
296 atomic_set(&tcon->num_t2renames, 0);
297 atomic_set(&tcon->num_ffirst, 0);
298 atomic_set(&tcon->num_fnext, 0);
299 atomic_set(&tcon->num_fclose, 0);
300 atomic_set(&tcon->num_hardlinks, 0);
301 atomic_set(&tcon->num_symlinks, 0);
302 atomic_set(&tcon->num_locks, 0);
304 read_unlock(&GlobalSMBSeslock);
311 cifs_stats_read(char *buf, char **beginBuffer, off_t offset,
312 int count, int *eof, void *data)
314 int item_length, i, length;
315 struct list_head *tmp;
316 struct cifsTconInfo *tcon;
318 *beginBuffer = buf + offset;
320 length = sprintf(buf,
321 "Resources in use\nCIFS Session: %d\n",
322 sesInfoAllocCount.counter);
325 sprintf(buf, "Share (unique mount targets): %d\n",
326 tconInfoAllocCount.counter);
327 length += item_length;
330 sprintf(buf, "SMB Request/Response Buffer: %d Pool size: %d\n",
331 bufAllocCount.counter,
332 cifs_min_rcv + tcpSesAllocCount.counter);
333 length += item_length;
336 sprintf(buf, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
337 smBufAllocCount.counter, cifs_min_small);
338 length += item_length;
340 #ifdef CONFIG_CIFS_STATS2
341 item_length = sprintf(buf, "Total Large %d Small %d Allocations\n",
342 atomic_read(&totBufAllocCount),
343 atomic_read(&totSmBufAllocCount));
344 length += item_length;
346 #endif /* CONFIG_CIFS_STATS2 */
349 sprintf(buf, "Operations (MIDs): %d\n",
351 length += item_length;
353 item_length = sprintf(buf,
354 "\n%d session %d share reconnects\n",
355 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
356 length += item_length;
359 item_length = sprintf(buf,
360 "Total vfs operations: %d maximum at one time: %d\n",
361 GlobalCurrentXid, GlobalMaxActiveXid);
362 length += item_length;
366 read_lock(&GlobalSMBSeslock);
367 list_for_each(tmp, &GlobalTreeConnectionList) {
369 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
370 item_length = sprintf(buf, "\n%d) %s", i, tcon->treeName);
372 length += item_length;
373 if (tcon->tidStatus == CifsNeedReconnect) {
374 buf += sprintf(buf, "\tDISCONNECTED ");
377 item_length = sprintf(buf, "\nSMBs: %d Oplock Breaks: %d",
378 atomic_read(&tcon->num_smbs_sent),
379 atomic_read(&tcon->num_oplock_brks));
381 length += item_length;
382 item_length = sprintf(buf, "\nReads: %d Bytes: %lld",
383 atomic_read(&tcon->num_reads),
384 (long long)(tcon->bytes_read));
386 length += item_length;
387 item_length = sprintf(buf, "\nWrites: %d Bytes: %lld",
388 atomic_read(&tcon->num_writes),
389 (long long)(tcon->bytes_written));
391 length += item_length;
392 item_length = sprintf(buf,
393 "\nLocks: %d HardLinks: %d Symlinks: %d",
394 atomic_read(&tcon->num_locks),
395 atomic_read(&tcon->num_hardlinks),
396 atomic_read(&tcon->num_symlinks));
398 length += item_length;
400 item_length = sprintf(buf, "\nOpens: %d Closes: %d Deletes: %d",
401 atomic_read(&tcon->num_opens),
402 atomic_read(&tcon->num_closes),
403 atomic_read(&tcon->num_deletes));
405 length += item_length;
406 item_length = sprintf(buf, "\nMkdirs: %d Rmdirs: %d",
407 atomic_read(&tcon->num_mkdirs),
408 atomic_read(&tcon->num_rmdirs));
410 length += item_length;
411 item_length = sprintf(buf, "\nRenames: %d T2 Renames %d",
412 atomic_read(&tcon->num_renames),
413 atomic_read(&tcon->num_t2renames));
415 length += item_length;
416 item_length = sprintf(buf, "\nFindFirst: %d FNext %d FClose %d",
417 atomic_read(&tcon->num_ffirst),
418 atomic_read(&tcon->num_fnext),
419 atomic_read(&tcon->num_fclose));
421 length += item_length;
423 read_unlock(&GlobalSMBSeslock);
425 buf += sprintf(buf, "\n");
428 if (offset + count >= length)
430 if (length < offset) {
434 length = length - offset;
443 static struct proc_dir_entry *proc_fs_cifs;
444 read_proc_t cifs_txanchor_read;
445 static read_proc_t cifsFYI_read;
446 static write_proc_t cifsFYI_write;
447 static read_proc_t oplockEnabled_read;
448 static write_proc_t oplockEnabled_write;
449 static read_proc_t lookupFlag_read;
450 static write_proc_t lookupFlag_write;
451 static read_proc_t traceSMB_read;
452 static write_proc_t traceSMB_write;
453 static read_proc_t multiuser_mount_read;
454 static write_proc_t multiuser_mount_write;
455 static read_proc_t security_flags_read;
456 static write_proc_t security_flags_write;
457 /* static read_proc_t ntlmv2_enabled_read;
458 static write_proc_t ntlmv2_enabled_write;
459 static read_proc_t packet_signing_enabled_read;
460 static write_proc_t packet_signing_enabled_write;*/
461 static read_proc_t experimEnabled_read;
462 static write_proc_t experimEnabled_write;
463 static read_proc_t linuxExtensionsEnabled_read;
464 static write_proc_t linuxExtensionsEnabled_write;
469 struct proc_dir_entry *pde;
471 proc_fs_cifs = proc_mkdir("cifs", proc_root_fs);
472 if (proc_fs_cifs == NULL)
475 proc_fs_cifs->owner = THIS_MODULE;
476 create_proc_read_entry("DebugData", 0, proc_fs_cifs,
477 cifs_debug_data_read, NULL);
479 #ifdef CONFIG_CIFS_STATS
480 pde = create_proc_read_entry("Stats", 0, proc_fs_cifs,
481 cifs_stats_read, NULL);
483 pde->write_proc = cifs_stats_write;
485 pde = create_proc_read_entry("cifsFYI", 0, proc_fs_cifs,
488 pde->write_proc = cifsFYI_write;
491 create_proc_read_entry("traceSMB", 0, proc_fs_cifs,
492 traceSMB_read, NULL);
494 pde->write_proc = traceSMB_write;
496 pde = create_proc_read_entry("OplockEnabled", 0, proc_fs_cifs,
497 oplockEnabled_read, NULL);
499 pde->write_proc = oplockEnabled_write;
501 pde = create_proc_read_entry("Experimental", 0, proc_fs_cifs,
502 experimEnabled_read, NULL);
504 pde->write_proc = experimEnabled_write;
506 pde = create_proc_read_entry("LinuxExtensionsEnabled", 0, proc_fs_cifs,
507 linuxExtensionsEnabled_read, NULL);
509 pde->write_proc = linuxExtensionsEnabled_write;
512 create_proc_read_entry("MultiuserMount", 0, proc_fs_cifs,
513 multiuser_mount_read, NULL);
515 pde->write_proc = multiuser_mount_write;
518 create_proc_read_entry("SecurityFlags", 0, proc_fs_cifs,
519 security_flags_read, NULL);
521 pde->write_proc = security_flags_write;
524 create_proc_read_entry("LookupCacheEnabled", 0, proc_fs_cifs,
525 lookupFlag_read, NULL);
527 pde->write_proc = lookupFlag_write;
530 create_proc_read_entry("NTLMV2Enabled", 0, proc_fs_cifs,
531 ntlmv2_enabled_read, NULL);
533 pde->write_proc = ntlmv2_enabled_write;
536 create_proc_read_entry("PacketSigningEnabled", 0, proc_fs_cifs,
537 packet_signing_enabled_read, NULL);
539 pde->write_proc = packet_signing_enabled_write;*/
543 cifs_proc_clean(void)
545 if (proc_fs_cifs == NULL)
548 remove_proc_entry("DebugData", proc_fs_cifs);
549 remove_proc_entry("cifsFYI", proc_fs_cifs);
550 remove_proc_entry("traceSMB", proc_fs_cifs);
551 #ifdef CONFIG_CIFS_STATS
552 remove_proc_entry("Stats", proc_fs_cifs);
554 remove_proc_entry("MultiuserMount", proc_fs_cifs);
555 remove_proc_entry("OplockEnabled", proc_fs_cifs);
556 /* remove_proc_entry("NTLMV2Enabled",proc_fs_cifs); */
557 remove_proc_entry("SecurityFlags", proc_fs_cifs);
558 /* remove_proc_entry("PacketSigningEnabled", proc_fs_cifs); */
559 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
560 remove_proc_entry("Experimental", proc_fs_cifs);
561 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
562 remove_proc_entry("cifs", proc_root_fs);
566 cifsFYI_read(char *page, char **start, off_t off, int count,
567 int *eof, void *data)
571 len = sprintf(page, "%d\n", cifsFYI);
587 cifsFYI_write(struct file *file, const char __user *buffer,
588 unsigned long count, void *data)
593 rc = get_user(c, buffer);
596 if (c == '0' || c == 'n' || c == 'N')
598 else if (c == '1' || c == 'y' || c == 'Y')
600 else if ((c > '1') && (c <= '9'))
601 cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
607 oplockEnabled_read(char *page, char **start, off_t off,
608 int count, int *eof, void *data)
612 len = sprintf(page, "%d\n", oplockEnabled);
628 oplockEnabled_write(struct file *file, const char __user *buffer,
629 unsigned long count, void *data)
634 rc = get_user(c, buffer);
637 if (c == '0' || c == 'n' || c == 'N')
639 else if (c == '1' || c == 'y' || c == 'Y')
646 experimEnabled_read(char *page, char **start, off_t off,
647 int count, int *eof, void *data)
651 len = sprintf(page, "%d\n", experimEnabled);
667 experimEnabled_write(struct file *file, const char __user *buffer,
668 unsigned long count, void *data)
673 rc = get_user(c, buffer);
676 if (c == '0' || c == 'n' || c == 'N')
678 else if (c == '1' || c == 'y' || c == 'Y')
687 linuxExtensionsEnabled_read(char *page, char **start, off_t off,
688 int count, int *eof, void *data)
692 len = sprintf(page, "%d\n", linuxExtEnabled);
707 linuxExtensionsEnabled_write(struct file *file, const char __user *buffer,
708 unsigned long count, void *data)
713 rc = get_user(c, buffer);
716 if (c == '0' || c == 'n' || c == 'N')
718 else if (c == '1' || c == 'y' || c == 'Y')
726 lookupFlag_read(char *page, char **start, off_t off,
727 int count, int *eof, void *data)
731 len = sprintf(page, "%d\n", lookupCacheEnabled);
747 lookupFlag_write(struct file *file, const char __user *buffer,
748 unsigned long count, void *data)
753 rc = get_user(c, buffer);
756 if (c == '0' || c == 'n' || c == 'N')
757 lookupCacheEnabled = 0;
758 else if (c == '1' || c == 'y' || c == 'Y')
759 lookupCacheEnabled = 1;
764 traceSMB_read(char *page, char **start, off_t off, int count,
765 int *eof, void *data)
769 len = sprintf(page, "%d\n", traceSMB);
785 traceSMB_write(struct file *file, const char __user *buffer,
786 unsigned long count, void *data)
791 rc = get_user(c, buffer);
794 if (c == '0' || c == 'n' || c == 'N')
796 else if (c == '1' || c == 'y' || c == 'Y')
803 multiuser_mount_read(char *page, char **start, off_t off,
804 int count, int *eof, void *data)
808 len = sprintf(page, "%d\n", multiuser_mount);
824 multiuser_mount_write(struct file *file, const char __user *buffer,
825 unsigned long count, void *data)
830 rc = get_user(c, buffer);
833 if (c == '0' || c == 'n' || c == 'N')
835 else if (c == '1' || c == 'y' || c == 'Y')
842 security_flags_read(char *page, char **start, off_t off,
843 int count, int *eof, void *data)
847 len = sprintf(page, "0x%x\n", extended_security);
863 security_flags_write(struct file *file, const char __user *buffer,
864 unsigned long count, void *data)
867 char flags_string[12];
870 if ((count < 1) || (count > 11))
873 memset(flags_string, 0, 12);
875 if (copy_from_user(flags_string, buffer, count))
879 /* single char or single char followed by null */
881 if (c == '0' || c == 'n' || c == 'N') {
882 extended_security = CIFSSEC_DEF; /* default */
884 } else if (c == '1' || c == 'y' || c == 'Y') {
885 extended_security = CIFSSEC_MAX;
887 } else if (!isdigit(c)) {
888 cERROR(1, ("invalid flag %c", c));
892 /* else we have a number */
894 flags = simple_strtoul(flags_string, NULL, 0);
896 cFYI(1, ("sec flags 0x%x", flags));
899 cERROR(1, ("invalid security flags %s", flags_string));
903 if (flags & ~CIFSSEC_MASK) {
904 cERROR(1, ("attempt to set unsupported security flags 0x%x",
905 flags & ~CIFSSEC_MASK));
908 /* flags look ok - update the global security flags for cifs module */
909 extended_security = flags;
910 if (extended_security & CIFSSEC_MUST_SIGN) {
911 /* requiring signing implies signing is allowed */
912 extended_security |= CIFSSEC_MAY_SIGN;
913 cFYI(1, ("packet signing now required"));
914 } else if ((extended_security & CIFSSEC_MAY_SIGN) == 0) {
915 cFYI(1, ("packet signing disabled"));
917 /* BB should we turn on MAY flags for other MUST options? */
921 inline void cifs_proc_init(void)
925 inline void cifs_proc_clean(void)