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);
212 length = sprintf(buf, "\n%d) %s Uses: %d ", i,
213 tcon->treeName, atomic_read(&tcon->useCount));
215 if (tcon->nativeFileSystem) {
216 length = sprintf(buf, "Type: %s ",
217 tcon->nativeFileSystem);
220 length = sprintf(buf, "DevInfo: 0x%x Attributes: 0x%x"
221 "\nPathComponentMax: %d Status: %d",
222 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
223 le32_to_cpu(tcon->fsAttrInfo.Attributes),
224 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
227 if (dev_type == FILE_DEVICE_DISK)
228 length = sprintf(buf, " type: DISK ");
229 else if (dev_type == FILE_DEVICE_CD_ROM)
230 length = sprintf(buf, " type: CDROM ");
233 sprintf(buf, " type: %d ", dev_type);
235 if (tcon->tidStatus == CifsNeedReconnect) {
236 buf += sprintf(buf, "\tDISCONNECTED ");
240 read_unlock(&GlobalSMBSeslock);
242 length = sprintf(buf, "\n");
245 /* BB add code to dump additional info such as TCP session info now */
246 /* Now calculate total size of returned data */
247 length = buf - original_buf;
249 if (offset + count >= length)
251 if (length < offset) {
255 length = length - offset;
263 #ifdef CONFIG_CIFS_STATS
266 cifs_stats_write(struct file *file, const char __user *buffer,
267 unsigned long count, void *data)
271 struct list_head *tmp;
272 struct cifsTconInfo *tcon;
274 rc = get_user(c, buffer);
278 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
279 read_lock(&GlobalSMBSeslock);
280 #ifdef CONFIG_CIFS_STATS2
281 atomic_set(&totBufAllocCount, 0);
282 atomic_set(&totSmBufAllocCount, 0);
283 #endif /* CONFIG_CIFS_STATS2 */
284 list_for_each(tmp, &GlobalTreeConnectionList) {
285 tcon = list_entry(tmp, struct cifsTconInfo,
287 atomic_set(&tcon->num_smbs_sent, 0);
288 atomic_set(&tcon->num_writes, 0);
289 atomic_set(&tcon->num_reads, 0);
290 atomic_set(&tcon->num_oplock_brks, 0);
291 atomic_set(&tcon->num_opens, 0);
292 atomic_set(&tcon->num_closes, 0);
293 atomic_set(&tcon->num_deletes, 0);
294 atomic_set(&tcon->num_mkdirs, 0);
295 atomic_set(&tcon->num_rmdirs, 0);
296 atomic_set(&tcon->num_renames, 0);
297 atomic_set(&tcon->num_t2renames, 0);
298 atomic_set(&tcon->num_ffirst, 0);
299 atomic_set(&tcon->num_fnext, 0);
300 atomic_set(&tcon->num_fclose, 0);
301 atomic_set(&tcon->num_hardlinks, 0);
302 atomic_set(&tcon->num_symlinks, 0);
303 atomic_set(&tcon->num_locks, 0);
305 read_unlock(&GlobalSMBSeslock);
312 cifs_stats_read(char *buf, char **beginBuffer, off_t offset,
313 int count, int *eof, void *data)
315 int item_length, i, length;
316 struct list_head *tmp;
317 struct cifsTconInfo *tcon;
319 *beginBuffer = buf + offset;
321 length = sprintf(buf,
322 "Resources in use\nCIFS Session: %d\n",
323 sesInfoAllocCount.counter);
326 sprintf(buf, "Share (unique mount targets): %d\n",
327 tconInfoAllocCount.counter);
328 length += item_length;
331 sprintf(buf, "SMB Request/Response Buffer: %d Pool size: %d\n",
332 bufAllocCount.counter,
333 cifs_min_rcv + tcpSesAllocCount.counter);
334 length += item_length;
337 sprintf(buf, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
338 smBufAllocCount.counter, cifs_min_small);
339 length += item_length;
341 #ifdef CONFIG_CIFS_STATS2
342 item_length = sprintf(buf, "Total Large %d Small %d Allocations\n",
343 atomic_read(&totBufAllocCount),
344 atomic_read(&totSmBufAllocCount));
345 length += item_length;
347 #endif /* CONFIG_CIFS_STATS2 */
350 sprintf(buf, "Operations (MIDs): %d\n",
352 length += item_length;
354 item_length = sprintf(buf,
355 "\n%d session %d share reconnects\n",
356 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
357 length += item_length;
360 item_length = sprintf(buf,
361 "Total vfs operations: %d maximum at one time: %d\n",
362 GlobalCurrentXid, GlobalMaxActiveXid);
363 length += item_length;
367 read_lock(&GlobalSMBSeslock);
368 list_for_each(tmp, &GlobalTreeConnectionList) {
370 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
371 item_length = sprintf(buf, "\n%d) %s", i, tcon->treeName);
373 length += item_length;
374 if (tcon->tidStatus == CifsNeedReconnect) {
375 buf += sprintf(buf, "\tDISCONNECTED ");
378 item_length = sprintf(buf, "\nSMBs: %d Oplock Breaks: %d",
379 atomic_read(&tcon->num_smbs_sent),
380 atomic_read(&tcon->num_oplock_brks));
382 length += item_length;
383 item_length = sprintf(buf, "\nReads: %d Bytes: %lld",
384 atomic_read(&tcon->num_reads),
385 (long long)(tcon->bytes_read));
387 length += item_length;
388 item_length = sprintf(buf, "\nWrites: %d Bytes: %lld",
389 atomic_read(&tcon->num_writes),
390 (long long)(tcon->bytes_written));
392 length += item_length;
393 item_length = sprintf(buf,
394 "\nLocks: %d HardLinks: %d Symlinks: %d",
395 atomic_read(&tcon->num_locks),
396 atomic_read(&tcon->num_hardlinks),
397 atomic_read(&tcon->num_symlinks));
399 length += item_length;
401 item_length = sprintf(buf, "\nOpens: %d Closes: %d Deletes: %d",
402 atomic_read(&tcon->num_opens),
403 atomic_read(&tcon->num_closes),
404 atomic_read(&tcon->num_deletes));
406 length += item_length;
407 item_length = sprintf(buf, "\nMkdirs: %d Rmdirs: %d",
408 atomic_read(&tcon->num_mkdirs),
409 atomic_read(&tcon->num_rmdirs));
411 length += item_length;
412 item_length = sprintf(buf, "\nRenames: %d T2 Renames %d",
413 atomic_read(&tcon->num_renames),
414 atomic_read(&tcon->num_t2renames));
416 length += item_length;
417 item_length = sprintf(buf, "\nFindFirst: %d FNext %d FClose %d",
418 atomic_read(&tcon->num_ffirst),
419 atomic_read(&tcon->num_fnext),
420 atomic_read(&tcon->num_fclose));
422 length += item_length;
424 read_unlock(&GlobalSMBSeslock);
426 buf += sprintf(buf, "\n");
429 if (offset + count >= length)
431 if (length < offset) {
435 length = length - offset;
444 static struct proc_dir_entry *proc_fs_cifs;
445 read_proc_t cifs_txanchor_read;
446 static read_proc_t cifsFYI_read;
447 static write_proc_t cifsFYI_write;
448 static read_proc_t oplockEnabled_read;
449 static write_proc_t oplockEnabled_write;
450 static read_proc_t lookupFlag_read;
451 static write_proc_t lookupFlag_write;
452 static read_proc_t traceSMB_read;
453 static write_proc_t traceSMB_write;
454 static read_proc_t multiuser_mount_read;
455 static write_proc_t multiuser_mount_write;
456 static read_proc_t security_flags_read;
457 static write_proc_t security_flags_write;
458 /* static read_proc_t ntlmv2_enabled_read;
459 static write_proc_t ntlmv2_enabled_write;
460 static read_proc_t packet_signing_enabled_read;
461 static write_proc_t packet_signing_enabled_write;*/
462 static read_proc_t experimEnabled_read;
463 static write_proc_t experimEnabled_write;
464 static read_proc_t linuxExtensionsEnabled_read;
465 static write_proc_t linuxExtensionsEnabled_write;
470 struct proc_dir_entry *pde;
472 proc_fs_cifs = proc_mkdir("cifs", proc_root_fs);
473 if (proc_fs_cifs == NULL)
476 proc_fs_cifs->owner = THIS_MODULE;
477 create_proc_read_entry("DebugData", 0, proc_fs_cifs,
478 cifs_debug_data_read, NULL);
480 #ifdef CONFIG_CIFS_STATS
481 pde = create_proc_read_entry("Stats", 0, proc_fs_cifs,
482 cifs_stats_read, NULL);
484 pde->write_proc = cifs_stats_write;
486 pde = create_proc_read_entry("cifsFYI", 0, proc_fs_cifs,
489 pde->write_proc = cifsFYI_write;
492 create_proc_read_entry("traceSMB", 0, proc_fs_cifs,
493 traceSMB_read, NULL);
495 pde->write_proc = traceSMB_write;
497 pde = create_proc_read_entry("OplockEnabled", 0, proc_fs_cifs,
498 oplockEnabled_read, NULL);
500 pde->write_proc = oplockEnabled_write;
502 pde = create_proc_read_entry("Experimental", 0, proc_fs_cifs,
503 experimEnabled_read, NULL);
505 pde->write_proc = experimEnabled_write;
507 pde = create_proc_read_entry("LinuxExtensionsEnabled", 0, proc_fs_cifs,
508 linuxExtensionsEnabled_read, NULL);
510 pde->write_proc = linuxExtensionsEnabled_write;
513 create_proc_read_entry("MultiuserMount", 0, proc_fs_cifs,
514 multiuser_mount_read, NULL);
516 pde->write_proc = multiuser_mount_write;
519 create_proc_read_entry("SecurityFlags", 0, proc_fs_cifs,
520 security_flags_read, NULL);
522 pde->write_proc = security_flags_write;
525 create_proc_read_entry("LookupCacheEnabled", 0, proc_fs_cifs,
526 lookupFlag_read, NULL);
528 pde->write_proc = lookupFlag_write;
531 create_proc_read_entry("NTLMV2Enabled", 0, proc_fs_cifs,
532 ntlmv2_enabled_read, NULL);
534 pde->write_proc = ntlmv2_enabled_write;
537 create_proc_read_entry("PacketSigningEnabled", 0, proc_fs_cifs,
538 packet_signing_enabled_read, NULL);
540 pde->write_proc = packet_signing_enabled_write;*/
544 cifs_proc_clean(void)
546 if (proc_fs_cifs == NULL)
549 remove_proc_entry("DebugData", proc_fs_cifs);
550 remove_proc_entry("cifsFYI", proc_fs_cifs);
551 remove_proc_entry("traceSMB", proc_fs_cifs);
552 #ifdef CONFIG_CIFS_STATS
553 remove_proc_entry("Stats", proc_fs_cifs);
555 remove_proc_entry("MultiuserMount", proc_fs_cifs);
556 remove_proc_entry("OplockEnabled", proc_fs_cifs);
557 /* remove_proc_entry("NTLMV2Enabled",proc_fs_cifs); */
558 remove_proc_entry("SecurityFlags", proc_fs_cifs);
559 /* remove_proc_entry("PacketSigningEnabled", proc_fs_cifs); */
560 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
561 remove_proc_entry("Experimental", proc_fs_cifs);
562 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
563 remove_proc_entry("cifs", proc_root_fs);
567 cifsFYI_read(char *page, char **start, off_t off, int count,
568 int *eof, void *data)
572 len = sprintf(page, "%d\n", cifsFYI);
588 cifsFYI_write(struct file *file, const char __user *buffer,
589 unsigned long count, void *data)
594 rc = get_user(c, buffer);
597 if (c == '0' || c == 'n' || c == 'N')
599 else if (c == '1' || c == 'y' || c == 'Y')
601 else if ((c > '1') && (c <= '9'))
602 cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
608 oplockEnabled_read(char *page, char **start, off_t off,
609 int count, int *eof, void *data)
613 len = sprintf(page, "%d\n", oplockEnabled);
629 oplockEnabled_write(struct file *file, const char __user *buffer,
630 unsigned long count, void *data)
635 rc = get_user(c, buffer);
638 if (c == '0' || c == 'n' || c == 'N')
640 else if (c == '1' || c == 'y' || c == 'Y')
647 experimEnabled_read(char *page, char **start, off_t off,
648 int count, int *eof, void *data)
652 len = sprintf(page, "%d\n", experimEnabled);
668 experimEnabled_write(struct file *file, const char __user *buffer,
669 unsigned long count, void *data)
674 rc = get_user(c, buffer);
677 if (c == '0' || c == 'n' || c == 'N')
679 else if (c == '1' || c == 'y' || c == 'Y')
688 linuxExtensionsEnabled_read(char *page, char **start, off_t off,
689 int count, int *eof, void *data)
693 len = sprintf(page, "%d\n", linuxExtEnabled);
708 linuxExtensionsEnabled_write(struct file *file, const char __user *buffer,
709 unsigned long count, void *data)
714 rc = get_user(c, buffer);
717 if (c == '0' || c == 'n' || c == 'N')
719 else if (c == '1' || c == 'y' || c == 'Y')
727 lookupFlag_read(char *page, char **start, off_t off,
728 int count, int *eof, void *data)
732 len = sprintf(page, "%d\n", lookupCacheEnabled);
748 lookupFlag_write(struct file *file, const char __user *buffer,
749 unsigned long count, void *data)
754 rc = get_user(c, buffer);
757 if (c == '0' || c == 'n' || c == 'N')
758 lookupCacheEnabled = 0;
759 else if (c == '1' || c == 'y' || c == 'Y')
760 lookupCacheEnabled = 1;
765 traceSMB_read(char *page, char **start, off_t off, int count,
766 int *eof, void *data)
770 len = sprintf(page, "%d\n", traceSMB);
786 traceSMB_write(struct file *file, const char __user *buffer,
787 unsigned long count, void *data)
792 rc = get_user(c, buffer);
795 if (c == '0' || c == 'n' || c == 'N')
797 else if (c == '1' || c == 'y' || c == 'Y')
804 multiuser_mount_read(char *page, char **start, off_t off,
805 int count, int *eof, void *data)
809 len = sprintf(page, "%d\n", multiuser_mount);
825 multiuser_mount_write(struct file *file, const char __user *buffer,
826 unsigned long count, void *data)
831 rc = get_user(c, buffer);
834 if (c == '0' || c == 'n' || c == 'N')
836 else if (c == '1' || c == 'y' || c == 'Y')
843 security_flags_read(char *page, char **start, off_t off,
844 int count, int *eof, void *data)
848 len = sprintf(page, "0x%x\n", extended_security);
864 security_flags_write(struct file *file, const char __user *buffer,
865 unsigned long count, void *data)
868 char flags_string[12];
871 if ((count < 1) || (count > 11))
874 memset(flags_string, 0, 12);
876 if (copy_from_user(flags_string, buffer, count))
880 /* single char or single char followed by null */
882 if (c == '0' || c == 'n' || c == 'N') {
883 extended_security = CIFSSEC_DEF; /* default */
885 } else if (c == '1' || c == 'y' || c == 'Y') {
886 extended_security = CIFSSEC_MAX;
888 } else if (!isdigit(c)) {
889 cERROR(1, ("invalid flag %c", c));
893 /* else we have a number */
895 flags = simple_strtoul(flags_string, NULL, 0);
897 cFYI(1, ("sec flags 0x%x", flags));
900 cERROR(1, ("invalid security flags %s", flags_string));
904 if (flags & ~CIFSSEC_MASK) {
905 cERROR(1, ("attempt to set unsupported security flags 0x%x",
906 flags & ~CIFSSEC_MASK));
909 /* flags look ok - update the global security flags for cifs module */
910 extended_security = flags;
911 if (extended_security & CIFSSEC_MUST_SIGN) {
912 /* requiring signing implies signing is allowed */
913 extended_security |= CIFSSEC_MAY_SIGN;
914 cFYI(1, ("packet signing now required"));
915 } else if ((extended_security & CIFSSEC_MAY_SIGN) == 0) {
916 cFYI(1, ("packet signing disabled"));
918 /* BB should we turn on MAY flags for other MUST options? */