initial commit with v2.6.9
[linux-2.6.9-moxart.git] / fs / cifs / cifs_debug.c
blob0cf2b223e49078d4636e4f42a22e0c341be40905
1 /*
2 * fs/cifs_debug.c
4 * Copyright (C) International Business Machines Corp., 2000,2003
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
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"
33 void
34 cifs_dump_mem(char *label, void *data, int length)
36 int i, j;
37 int *intptr = data;
38 char *charptr = data;
39 char buf[10], line[80];
41 printk(KERN_DEBUG "%s: dump of %d bytes of data at 0x%p\n\n",
42 label, length, data);
43 for (i = 0; i < length; i += 16) {
44 line[0] = 0;
45 for (j = 0; (j < 4) && (i + j * 4 < length); j++) {
46 sprintf(buf, " %08x", intptr[i / 4 + j]);
47 strcat(line, buf);
49 buf[0] = ' ';
50 buf[2] = 0;
51 for (j = 0; (j < 16) && (i + j < length); j++) {
52 buf[1] = isprint(charptr[i + j]) ? charptr[i + j] : '.';
53 strcat(line, buf);
55 printk(KERN_DEBUG "%s\n", line);
59 #ifdef CONFIG_PROC_FS
60 int
61 cifs_debug_data_read(char *buf, char **beginBuffer, off_t offset,
62 int count, int *eof, void *data)
64 struct list_head *tmp;
65 struct list_head *tmp1;
66 struct mid_q_entry * mid_entry;
67 struct cifsSesInfo *ses;
68 struct cifsTconInfo *tcon;
69 int i;
70 int length = 0;
71 char * original_buf = buf;
73 *beginBuffer = buf + offset;
76 length =
77 sprintf(buf,
78 "Display Internal CIFS Data Structures for Debugging\n"
79 "---------------------------------------------------\n");
80 buf += length;
82 length = sprintf(buf, "Servers:\n");
83 buf += length;
85 i = 0;
86 read_lock(&GlobalSMBSeslock);
87 list_for_each(tmp, &GlobalSMBSessionList) {
88 i++;
89 ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
90 length =
91 sprintf(buf,
92 "\n%d) Name: %s Domain: %s Mounts: %d ServerOS: %s \n\tServerNOS: %s\tCapabilities: 0x%x\n\tSMB session status: %d\tTCP status: %d",
93 i, ses->serverName, ses->serverDomain, atomic_read(&ses->inUse),
94 ses->serverOS, ses->serverNOS, ses->capabilities,ses->status,ses->server->tcpStatus);
95 buf += length;
96 if(ses->server) {
97 buf += sprintf(buf, "\n\tLocal Users To Server: %d SecMode: 0x%x Req Active: %d",
98 atomic_read(&ses->server->socketUseCount),
99 ses->server->secMode,
100 atomic_read(&ses->server->inFlight));
102 length = sprintf(buf, "\nMIDs: \n");
103 buf += length;
105 spin_lock(&GlobalMid_Lock);
106 list_for_each(tmp1, &ses->server->pending_mid_q) {
107 mid_entry = list_entry(tmp1, struct
108 mid_q_entry,
109 qhead);
110 if(mid_entry) {
111 length = sprintf(buf,"State: %d com: %d pid: %d tsk: %p mid %d\n",mid_entry->midState,mid_entry->command,mid_entry->pid,mid_entry->tsk,mid_entry->mid);
112 buf += length;
115 spin_unlock(&GlobalMid_Lock);
119 read_unlock(&GlobalSMBSeslock);
120 sprintf(buf, "\n");
121 buf++;
123 length = sprintf(buf, "\nShares:\n");
124 buf += length;
126 i = 0;
127 read_lock(&GlobalSMBSeslock);
128 list_for_each(tmp, &GlobalTreeConnectionList) {
129 __u32 dev_type;
130 i++;
131 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
132 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
133 length =
134 sprintf(buf,
135 "\n%d) %s Uses: %d Type: %s Characteristics: 0x%x Attributes: 0x%x\nPathComponentMax: %d Status: %d",
136 i, tcon->treeName,
137 atomic_read(&tcon->useCount),
138 tcon->nativeFileSystem,
139 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
140 le32_to_cpu(tcon->fsAttrInfo.Attributes),
141 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
142 tcon->tidStatus);
143 buf += length;
144 if (dev_type == FILE_DEVICE_DISK)
145 length = sprintf(buf, " type: DISK ");
146 else if (dev_type == FILE_DEVICE_CD_ROM)
147 length = sprintf(buf, " type: CDROM ");
148 else
149 length =
150 sprintf(buf, " type: %d ", dev_type);
151 buf += length;
152 if(tcon->tidStatus == CifsNeedReconnect) {
153 buf += sprintf(buf, "\tDISCONNECTED ");
154 length += 14;
157 read_unlock(&GlobalSMBSeslock);
159 length = sprintf(buf, "\n");
160 buf += length;
162 /* BB add code to dump additional info such as TCP session info now */
163 /* Now calculate total size of returned data */
164 length = buf - original_buf;
166 if(offset + count >= length)
167 *eof = 1;
168 if(length < offset) {
169 *eof = 1;
170 return 0;
171 } else {
172 length = length - offset;
174 if (length > count)
175 length = count;
177 return length;
180 #ifdef CONFIG_CIFS_STATS
182 cifs_stats_read(char *buf, char **beginBuffer, off_t offset,
183 int count, int *eof, void *data)
185 int item_length,i,length;
186 struct list_head *tmp;
187 struct cifsTconInfo *tcon;
189 *beginBuffer = buf + offset;
191 length = sprintf(buf,
192 "Resources in use\nCIFS Session: %d\n",
193 sesInfoAllocCount.counter);
194 buf += length;
195 item_length =
196 sprintf(buf,"Share (unique mount targets): %d\n",
197 tconInfoAllocCount.counter);
198 length += item_length;
199 buf += item_length;
200 item_length =
201 sprintf(buf,"SMB Request/Response Buffer: %d\n",
202 bufAllocCount.counter);
203 length += item_length;
204 buf += item_length;
205 item_length =
206 sprintf(buf,"Operations (MIDs): %d\n",
207 midCount.counter);
208 length += item_length;
209 buf += item_length;
210 item_length = sprintf(buf,
211 "\n%d session %d share reconnects\n",
212 tcpSesReconnectCount.counter,tconInfoReconnectCount.counter);
213 length += item_length;
214 buf += item_length;
216 item_length = sprintf(buf,
217 "Total vfs operations: %d maximum at one time: %d\n",
218 GlobalCurrentXid,GlobalMaxActiveXid);
219 length += item_length;
220 buf += item_length;
222 i = 0;
223 read_lock(&GlobalSMBSeslock);
224 list_for_each(tmp, &GlobalTreeConnectionList) {
225 i++;
226 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
227 item_length = sprintf(buf,"\n%d) %s",i, tcon->treeName);
228 buf += item_length;
229 length += item_length;
230 if(tcon->tidStatus == CifsNeedReconnect) {
231 buf += sprintf(buf, "\tDISCONNECTED ");
232 length += 14;
234 item_length = sprintf(buf,"\nSMBs: %d Oplock Breaks: %d",
235 atomic_read(&tcon->num_smbs_sent),
236 atomic_read(&tcon->num_oplock_brks));
237 buf += item_length;
238 length += item_length;
239 item_length = sprintf(buf,"\nReads: %d Bytes %lld",
240 atomic_read(&tcon->num_reads),
241 (long long)(tcon->bytes_read));
242 buf += item_length;
243 length += item_length;
244 item_length = sprintf(buf,"\nWrites: %d Bytes: %lld",
245 atomic_read(&tcon->num_writes),
246 (long long)(tcon->bytes_written));
247 buf += item_length;
248 length += item_length;
249 item_length = sprintf(buf,
250 "\nOpens: %d Deletes: %d\nMkdirs: %d Rmdirs: %d",
251 atomic_read(&tcon->num_opens),
252 atomic_read(&tcon->num_deletes),
253 atomic_read(&tcon->num_mkdirs),
254 atomic_read(&tcon->num_rmdirs));
255 buf += item_length;
256 length += item_length;
257 item_length = sprintf(buf,
258 "\nRenames: %d T2 Renames %d",
259 atomic_read(&tcon->num_renames),
260 atomic_read(&tcon->num_t2renames));
261 buf += item_length;
262 length += item_length;
264 read_unlock(&GlobalSMBSeslock);
266 buf += sprintf(buf,"\n");
267 length++;
269 if(offset + count >= length)
270 *eof = 1;
271 if(length < offset) {
272 *eof = 1;
273 return 0;
274 } else {
275 length = length - offset;
277 if (length > count)
278 length = count;
280 return length;
282 #endif
284 struct proc_dir_entry *proc_fs_cifs;
285 read_proc_t cifs_txanchor_read;
286 static read_proc_t cifsFYI_read;
287 static write_proc_t cifsFYI_write;
288 static read_proc_t oplockEnabled_read;
289 static write_proc_t oplockEnabled_write;
290 static read_proc_t lookupFlag_read;
291 static write_proc_t lookupFlag_write;
292 static read_proc_t traceSMB_read;
293 static write_proc_t traceSMB_write;
294 static read_proc_t multiuser_mount_read;
295 static write_proc_t multiuser_mount_write;
296 static read_proc_t extended_security_read;
297 static write_proc_t extended_security_write;
298 static read_proc_t ntlmv2_enabled_read;
299 static write_proc_t ntlmv2_enabled_write;
300 static read_proc_t packet_signing_enabled_read;
301 static write_proc_t packet_signing_enabled_write;
302 static read_proc_t quotaEnabled_read;
303 static write_proc_t quotaEnabled_write;
304 static read_proc_t linuxExtensionsEnabled_read;
305 static write_proc_t linuxExtensionsEnabled_write;
307 void
308 cifs_proc_init(void)
310 struct proc_dir_entry *pde;
312 proc_fs_cifs = proc_mkdir("cifs", proc_root_fs);
313 if (proc_fs_cifs == NULL)
314 return;
316 proc_fs_cifs->owner = THIS_MODULE;
317 create_proc_read_entry("DebugData", 0, proc_fs_cifs,
318 cifs_debug_data_read, NULL);
320 #ifdef CONFIG_CIFS_STATS
321 create_proc_read_entry("Stats", 0, proc_fs_cifs,
322 cifs_stats_read, NULL);
323 #endif
324 pde = create_proc_read_entry("cifsFYI", 0, proc_fs_cifs,
325 cifsFYI_read, NULL);
326 if (pde)
327 pde->write_proc = cifsFYI_write;
329 pde =
330 create_proc_read_entry("traceSMB", 0, proc_fs_cifs,
331 traceSMB_read, NULL);
332 if (pde)
333 pde->write_proc = traceSMB_write;
335 pde = create_proc_read_entry("OplockEnabled", 0, proc_fs_cifs,
336 oplockEnabled_read, NULL);
337 if (pde)
338 pde->write_proc = oplockEnabled_write;
340 pde = create_proc_read_entry("QuotaEnabled", 0, proc_fs_cifs,
341 quotaEnabled_read, NULL);
342 if (pde)
343 pde->write_proc = quotaEnabled_write;
345 pde = create_proc_read_entry("LinuxExtensionsEnabled", 0, proc_fs_cifs,
346 linuxExtensionsEnabled_read, NULL);
347 if (pde)
348 pde->write_proc = linuxExtensionsEnabled_write;
350 pde =
351 create_proc_read_entry("MultiuserMount", 0, proc_fs_cifs,
352 multiuser_mount_read, NULL);
353 if (pde)
354 pde->write_proc = multiuser_mount_write;
356 pde =
357 create_proc_read_entry("ExtendedSecurity", 0, proc_fs_cifs,
358 extended_security_read, NULL);
359 if (pde)
360 pde->write_proc = extended_security_write;
362 pde =
363 create_proc_read_entry("LookupCacheEnabled", 0, proc_fs_cifs,
364 lookupFlag_read, NULL);
365 if (pde)
366 pde->write_proc = lookupFlag_write;
368 pde =
369 create_proc_read_entry("NTLMV2Enabled", 0, proc_fs_cifs,
370 ntlmv2_enabled_read, NULL);
371 if (pde)
372 pde->write_proc = ntlmv2_enabled_write;
374 pde =
375 create_proc_read_entry("PacketSigningEnabled", 0, proc_fs_cifs,
376 packet_signing_enabled_read, NULL);
377 if (pde)
378 pde->write_proc = packet_signing_enabled_write;
381 void
382 cifs_proc_clean(void)
384 if (proc_fs_cifs == NULL)
385 return;
387 remove_proc_entry("DebugData", proc_fs_cifs);
388 remove_proc_entry("cifsFYI", proc_fs_cifs);
389 remove_proc_entry("traceSMB", proc_fs_cifs);
390 #ifdef CONFIG_CIFS_STATS
391 remove_proc_entry("Stats", proc_fs_cifs);
392 #endif
393 remove_proc_entry("MultiuserMount", proc_fs_cifs);
394 remove_proc_entry("OplockEnabled", proc_fs_cifs);
395 remove_proc_entry("NTLMV2Enabled",proc_fs_cifs);
396 remove_proc_entry("ExtendedSecurity",proc_fs_cifs);
397 remove_proc_entry("PacketSigningEnabled",proc_fs_cifs);
398 remove_proc_entry("LinuxExtensionsEnabled",proc_fs_cifs);
399 remove_proc_entry("QuotaEnabled",proc_fs_cifs);
400 remove_proc_entry("LookupCacheEnabled",proc_fs_cifs);
401 remove_proc_entry("cifs", proc_root_fs);
404 static int
405 cifsFYI_read(char *page, char **start, off_t off, int count,
406 int *eof, void *data)
408 int len;
410 len = sprintf(page, "%d\n", cifsFYI);
412 len -= off;
413 *start = page + off;
415 if (len > count)
416 len = count;
417 else
418 *eof = 1;
420 if (len < 0)
421 len = 0;
423 return len;
425 static int
426 cifsFYI_write(struct file *file, const char __user *buffer,
427 unsigned long count, void *data)
429 char c;
430 int rc;
432 rc = get_user(c, buffer);
433 if (rc)
434 return rc;
435 if (c == '0' || c == 'n' || c == 'N')
436 cifsFYI = 0;
437 else if (c == '1' || c == 'y' || c == 'Y')
438 cifsFYI = 1;
440 return count;
443 static int
444 oplockEnabled_read(char *page, char **start, off_t off,
445 int count, int *eof, void *data)
447 int len;
449 len = sprintf(page, "%d\n", oplockEnabled);
451 len -= off;
452 *start = page + off;
454 if (len > count)
455 len = count;
456 else
457 *eof = 1;
459 if (len < 0)
460 len = 0;
462 return len;
464 static int
465 oplockEnabled_write(struct file *file, const char __user *buffer,
466 unsigned long count, void *data)
468 char c;
469 int rc;
471 rc = get_user(c, buffer);
472 if (rc)
473 return rc;
474 if (c == '0' || c == 'n' || c == 'N')
475 oplockEnabled = 0;
476 else if (c == '1' || c == 'y' || c == 'Y')
477 oplockEnabled = 1;
479 return count;
482 static int
483 quotaEnabled_read(char *page, char **start, off_t off,
484 int count, int *eof, void *data)
486 int len;
488 len = sprintf(page, "%d\n", quotaEnabled);
489 /* could also check if quotas are enabled in kernel
490 as a whole first */
491 len -= off;
492 *start = page + off;
494 if (len > count)
495 len = count;
496 else
497 *eof = 1;
499 if (len < 0)
500 len = 0;
502 return len;
504 static int
505 quotaEnabled_write(struct file *file, const char __user *buffer,
506 unsigned long count, void *data)
508 char c;
509 int rc;
511 rc = get_user(c, buffer);
512 if (rc)
513 return rc;
514 if (c == '0' || c == 'n' || c == 'N')
515 quotaEnabled = 0;
516 else if (c == '1' || c == 'y' || c == 'Y')
517 quotaEnabled = 1;
519 return count;
522 static int
523 linuxExtensionsEnabled_read(char *page, char **start, off_t off,
524 int count, int *eof, void *data)
526 int len;
528 len = sprintf(page, "%d\n", linuxExtEnabled);
529 /* could also check if quotas are enabled in kernel
530 as a whole first */
531 len -= off;
532 *start = page + off;
534 if (len > count)
535 len = count;
536 else
537 *eof = 1;
539 if (len < 0)
540 len = 0;
542 return len;
544 static int
545 linuxExtensionsEnabled_write(struct file *file, const char __user *buffer,
546 unsigned long count, void *data)
548 char c;
549 int rc;
551 rc = get_user(c, buffer);
552 if (rc)
553 return rc;
554 if (c == '0' || c == 'n' || c == 'N')
555 linuxExtEnabled = 0;
556 else if (c == '1' || c == 'y' || c == 'Y')
557 linuxExtEnabled = 1;
559 return count;
563 static int
564 lookupFlag_read(char *page, char **start, off_t off,
565 int count, int *eof, void *data)
567 int len;
569 len = sprintf(page, "%d\n", lookupCacheEnabled);
571 len -= off;
572 *start = page + off;
574 if (len > count)
575 len = count;
576 else
577 *eof = 1;
579 if (len < 0)
580 len = 0;
582 return len;
584 static int
585 lookupFlag_write(struct file *file, const char __user *buffer,
586 unsigned long count, void *data)
588 char c;
589 int rc;
591 rc = get_user(c, buffer);
592 if (rc)
593 return rc;
594 if (c == '0' || c == 'n' || c == 'N')
595 lookupCacheEnabled = 0;
596 else if (c == '1' || c == 'y' || c == 'Y')
597 lookupCacheEnabled = 1;
599 return count;
601 static int
602 traceSMB_read(char *page, char **start, off_t off, int count,
603 int *eof, void *data)
605 int len;
607 len = sprintf(page, "%d\n", traceSMB);
609 len -= off;
610 *start = page + off;
612 if (len > count)
613 len = count;
614 else
615 *eof = 1;
617 if (len < 0)
618 len = 0;
620 return len;
622 static int
623 traceSMB_write(struct file *file, const char __user *buffer,
624 unsigned long count, void *data)
626 char c;
627 int rc;
629 rc = get_user(c, buffer);
630 if (rc)
631 return rc;
632 if (c == '0' || c == 'n' || c == 'N')
633 traceSMB = 0;
634 else if (c == '1' || c == 'y' || c == 'Y')
635 traceSMB = 1;
637 return count;
640 static int
641 multiuser_mount_read(char *page, char **start, off_t off,
642 int count, int *eof, void *data)
644 int len;
646 len = sprintf(page, "%d\n", multiuser_mount);
648 len -= off;
649 *start = page + off;
651 if (len > count)
652 len = count;
653 else
654 *eof = 1;
656 if (len < 0)
657 len = 0;
659 return len;
661 static int
662 multiuser_mount_write(struct file *file, const char __user *buffer,
663 unsigned long count, void *data)
665 char c;
666 int rc;
668 rc = get_user(c, buffer);
669 if (rc)
670 return rc;
671 if (c == '0' || c == 'n' || c == 'N')
672 multiuser_mount = 0;
673 else if (c == '1' || c == 'y' || c == 'Y')
674 multiuser_mount = 1;
676 return count;
679 static int
680 extended_security_read(char *page, char **start, off_t off,
681 int count, int *eof, void *data)
683 int len;
685 len = sprintf(page, "%d\n", extended_security);
687 len -= off;
688 *start = page + off;
690 if (len > count)
691 len = count;
692 else
693 *eof = 1;
695 if (len < 0)
696 len = 0;
698 return len;
700 static int
701 extended_security_write(struct file *file, const char __user *buffer,
702 unsigned long count, void *data)
704 char c;
705 int rc;
707 rc = get_user(c, buffer);
708 if (rc)
709 return rc;
710 if (c == '0' || c == 'n' || c == 'N')
711 extended_security = 0;
712 else if (c == '1' || c == 'y' || c == 'Y')
713 extended_security = 1;
715 return count;
718 static int
719 ntlmv2_enabled_read(char *page, char **start, off_t off,
720 int count, int *eof, void *data)
722 int len;
724 len = sprintf(page, "%d\n", ntlmv2_support);
726 len -= off;
727 *start = page + off;
729 if (len > count)
730 len = count;
731 else
732 *eof = 1;
734 if (len < 0)
735 len = 0;
737 return len;
739 static int
740 ntlmv2_enabled_write(struct file *file, const char __user *buffer,
741 unsigned long count, void *data)
743 char c;
744 int rc;
746 rc = get_user(c, buffer);
747 if (rc)
748 return rc;
749 if (c == '0' || c == 'n' || c == 'N')
750 ntlmv2_support = 0;
751 else if (c == '1' || c == 'y' || c == 'Y')
752 ntlmv2_support = 1;
754 return count;
757 static int
758 packet_signing_enabled_read(char *page, char **start, off_t off,
759 int count, int *eof, void *data)
761 int len;
763 len = sprintf(page, "%d\n", sign_CIFS_PDUs);
765 len -= off;
766 *start = page + off;
768 if (len > count)
769 len = count;
770 else
771 *eof = 1;
773 if (len < 0)
774 len = 0;
776 return len;
778 static int
779 packet_signing_enabled_write(struct file *file, const char __user *buffer,
780 unsigned long count, void *data)
782 char c;
783 int rc;
785 rc = get_user(c, buffer);
786 if (rc)
787 return rc;
788 if (c == '0' || c == 'n' || c == 'N')
789 sign_CIFS_PDUs = 0;
790 else if (c == '1' || c == 'y' || c == 'Y')
791 sign_CIFS_PDUs = 1;
792 else if (c == '2')
793 sign_CIFS_PDUs = 2;
795 return count;
799 #endif