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
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\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);
62 cifs_debug_data_read(char *buf, char **beginBuffer, off_t offset,
63 int count, int *eof, void *data)
65 struct list_head *tmp;
66 struct list_head *tmp1;
67 struct mid_q_entry * mid_entry;
68 struct cifsSesInfo *ses;
69 struct cifsTconInfo *tcon;
72 char * original_buf = buf;
74 *beginBuffer = buf + offset;
79 "Display Internal CIFS Data Structures for Debugging\n"
80 "---------------------------------------------------\n");
82 length = sprintf(buf,"CIFS Version %s\n",CIFS_VERSION);
84 length = sprintf(buf, "Servers:");
88 read_lock(&GlobalSMBSeslock);
89 list_for_each(tmp, &GlobalSMBSessionList) {
91 ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
94 "\n%d) Name: %s Domain: %s Mounts: %d ServerOS: %s \n\tServerNOS: %s\tCapabilities: 0x%x\n\tSMB session status: %d\t",
95 i, ses->serverName, ses->serverDomain, atomic_read(&ses->inUse),
96 ses->serverOS, ses->serverNOS, ses->capabilities,ses->status);
99 buf += sprintf(buf, "TCP status: %d\n\tLocal Users To Server: %d SecMode: 0x%x Req Active: %d",
100 ses->server->tcpStatus,
101 atomic_read(&ses->server->socketUseCount),
102 ses->server->secMode,
103 atomic_read(&ses->server->inFlight));
105 length = sprintf(buf, "\nMIDs:\n");
108 spin_lock(&GlobalMid_Lock);
109 list_for_each(tmp1, &ses->server->pending_mid_q) {
110 mid_entry = list_entry(tmp1, struct
114 length = sprintf(buf,"State: %d com: %d pid: %d tsk: %p mid %d\n",
116 (int)mid_entry->command,
123 spin_unlock(&GlobalMid_Lock);
127 read_unlock(&GlobalSMBSeslock);
131 length = sprintf(buf, "Shares:");
135 read_lock(&GlobalSMBSeslock);
136 list_for_each(tmp, &GlobalTreeConnectionList) {
139 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
140 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
143 "\n%d) %s Uses: %d Type: %s Characteristics: 0x%x Attributes: 0x%x\nPathComponentMax: %d Status: %d",
145 atomic_read(&tcon->useCount),
146 tcon->nativeFileSystem,
147 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
148 le32_to_cpu(tcon->fsAttrInfo.Attributes),
149 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
152 if (dev_type == FILE_DEVICE_DISK)
153 length = sprintf(buf, " type: DISK ");
154 else if (dev_type == FILE_DEVICE_CD_ROM)
155 length = sprintf(buf, " type: CDROM ");
158 sprintf(buf, " type: %d ", dev_type);
160 if(tcon->tidStatus == CifsNeedReconnect) {
161 buf += sprintf(buf, "\tDISCONNECTED ");
165 read_unlock(&GlobalSMBSeslock);
167 length = sprintf(buf, "\n");
170 /* BB add code to dump additional info such as TCP session info now */
171 /* Now calculate total size of returned data */
172 length = buf - original_buf;
174 if(offset + count >= length)
176 if(length < offset) {
180 length = length - offset;
188 #ifdef CONFIG_CIFS_STATS
190 cifs_stats_read(char *buf, char **beginBuffer, off_t offset,
191 int count, int *eof, void *data)
193 int item_length,i,length;
194 struct list_head *tmp;
195 struct cifsTconInfo *tcon;
197 *beginBuffer = buf + offset;
199 length = sprintf(buf,
200 "Resources in use\nCIFS Session: %d\n",
201 sesInfoAllocCount.counter);
204 sprintf(buf,"Share (unique mount targets): %d\n",
205 tconInfoAllocCount.counter);
206 length += item_length;
209 sprintf(buf,"SMB Request/Response Buffer: %d Pool size: %d\n",
210 bufAllocCount.counter,cifs_min_rcv + tcpSesAllocCount.counter);
211 length += item_length;
214 sprintf(buf,"SMB Small Req/Resp Buffer: %d Pool size: %d\n",
215 smBufAllocCount.counter,cifs_min_small);
216 length += item_length;
219 sprintf(buf,"Operations (MIDs): %d\n",
221 length += item_length;
223 item_length = sprintf(buf,
224 "\n%d session %d share reconnects\n",
225 tcpSesReconnectCount.counter,tconInfoReconnectCount.counter);
226 length += item_length;
229 item_length = sprintf(buf,
230 "Total vfs operations: %d maximum at one time: %d\n",
231 GlobalCurrentXid,GlobalMaxActiveXid);
232 length += item_length;
236 read_lock(&GlobalSMBSeslock);
237 list_for_each(tmp, &GlobalTreeConnectionList) {
239 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
240 item_length = sprintf(buf,"\n%d) %s",i, tcon->treeName);
242 length += item_length;
243 if(tcon->tidStatus == CifsNeedReconnect) {
244 buf += sprintf(buf, "\tDISCONNECTED ");
247 item_length = sprintf(buf,"\nSMBs: %d Oplock Breaks: %d",
248 atomic_read(&tcon->num_smbs_sent),
249 atomic_read(&tcon->num_oplock_brks));
251 length += item_length;
252 item_length = sprintf(buf,"\nReads: %d Bytes %lld",
253 atomic_read(&tcon->num_reads),
254 (long long)(tcon->bytes_read));
256 length += item_length;
257 item_length = sprintf(buf,"\nWrites: %d Bytes: %lld",
258 atomic_read(&tcon->num_writes),
259 (long long)(tcon->bytes_written));
261 length += item_length;
262 item_length = sprintf(buf,
263 "\nOpens: %d Deletes: %d\nMkdirs: %d Rmdirs: %d",
264 atomic_read(&tcon->num_opens),
265 atomic_read(&tcon->num_deletes),
266 atomic_read(&tcon->num_mkdirs),
267 atomic_read(&tcon->num_rmdirs));
269 length += item_length;
270 item_length = sprintf(buf,
271 "\nRenames: %d T2 Renames %d",
272 atomic_read(&tcon->num_renames),
273 atomic_read(&tcon->num_t2renames));
275 length += item_length;
277 read_unlock(&GlobalSMBSeslock);
279 buf += sprintf(buf,"\n");
282 if(offset + count >= length)
284 if(length < offset) {
288 length = length - offset;
297 static struct proc_dir_entry *proc_fs_cifs;
298 read_proc_t cifs_txanchor_read;
299 static read_proc_t cifsFYI_read;
300 static write_proc_t cifsFYI_write;
301 static read_proc_t oplockEnabled_read;
302 static write_proc_t oplockEnabled_write;
303 static read_proc_t lookupFlag_read;
304 static write_proc_t lookupFlag_write;
305 static read_proc_t traceSMB_read;
306 static write_proc_t traceSMB_write;
307 static read_proc_t multiuser_mount_read;
308 static write_proc_t multiuser_mount_write;
309 static read_proc_t extended_security_read;
310 static write_proc_t extended_security_write;
311 static read_proc_t ntlmv2_enabled_read;
312 static write_proc_t ntlmv2_enabled_write;
313 static read_proc_t packet_signing_enabled_read;
314 static write_proc_t packet_signing_enabled_write;
315 static read_proc_t quotaEnabled_read;
316 static write_proc_t quotaEnabled_write;
317 static read_proc_t linuxExtensionsEnabled_read;
318 static write_proc_t linuxExtensionsEnabled_write;
323 struct proc_dir_entry *pde;
325 proc_fs_cifs = proc_mkdir("cifs", proc_root_fs);
326 if (proc_fs_cifs == NULL)
329 proc_fs_cifs->owner = THIS_MODULE;
330 create_proc_read_entry("DebugData", 0, proc_fs_cifs,
331 cifs_debug_data_read, NULL);
333 #ifdef CONFIG_CIFS_STATS
334 create_proc_read_entry("Stats", 0, proc_fs_cifs,
335 cifs_stats_read, NULL);
337 pde = create_proc_read_entry("cifsFYI", 0, proc_fs_cifs,
340 pde->write_proc = cifsFYI_write;
343 create_proc_read_entry("traceSMB", 0, proc_fs_cifs,
344 traceSMB_read, NULL);
346 pde->write_proc = traceSMB_write;
348 pde = create_proc_read_entry("OplockEnabled", 0, proc_fs_cifs,
349 oplockEnabled_read, NULL);
351 pde->write_proc = oplockEnabled_write;
353 pde = create_proc_read_entry("ReenableOldCifsReaddirCode", 0, proc_fs_cifs,
354 quotaEnabled_read, NULL);
356 pde->write_proc = quotaEnabled_write;
358 pde = create_proc_read_entry("LinuxExtensionsEnabled", 0, proc_fs_cifs,
359 linuxExtensionsEnabled_read, NULL);
361 pde->write_proc = linuxExtensionsEnabled_write;
364 create_proc_read_entry("MultiuserMount", 0, proc_fs_cifs,
365 multiuser_mount_read, NULL);
367 pde->write_proc = multiuser_mount_write;
370 create_proc_read_entry("ExtendedSecurity", 0, proc_fs_cifs,
371 extended_security_read, NULL);
373 pde->write_proc = extended_security_write;
376 create_proc_read_entry("LookupCacheEnabled", 0, proc_fs_cifs,
377 lookupFlag_read, NULL);
379 pde->write_proc = lookupFlag_write;
382 create_proc_read_entry("NTLMV2Enabled", 0, proc_fs_cifs,
383 ntlmv2_enabled_read, NULL);
385 pde->write_proc = ntlmv2_enabled_write;
388 create_proc_read_entry("PacketSigningEnabled", 0, proc_fs_cifs,
389 packet_signing_enabled_read, NULL);
391 pde->write_proc = packet_signing_enabled_write;
395 cifs_proc_clean(void)
397 if (proc_fs_cifs == NULL)
400 remove_proc_entry("DebugData", proc_fs_cifs);
401 remove_proc_entry("cifsFYI", proc_fs_cifs);
402 remove_proc_entry("traceSMB", proc_fs_cifs);
403 #ifdef CONFIG_CIFS_STATS
404 remove_proc_entry("Stats", proc_fs_cifs);
406 remove_proc_entry("MultiuserMount", proc_fs_cifs);
407 remove_proc_entry("OplockEnabled", proc_fs_cifs);
408 remove_proc_entry("NTLMV2Enabled",proc_fs_cifs);
409 remove_proc_entry("ExtendedSecurity",proc_fs_cifs);
410 remove_proc_entry("PacketSigningEnabled",proc_fs_cifs);
411 remove_proc_entry("LinuxExtensionsEnabled",proc_fs_cifs);
412 remove_proc_entry("ReenableOldCifsReaddirCode",proc_fs_cifs);
413 remove_proc_entry("LookupCacheEnabled",proc_fs_cifs);
414 remove_proc_entry("cifs", proc_root_fs);
418 cifsFYI_read(char *page, char **start, off_t off, int count,
419 int *eof, void *data)
423 len = sprintf(page, "%d\n", cifsFYI);
439 cifsFYI_write(struct file *file, const char __user *buffer,
440 unsigned long count, void *data)
445 rc = get_user(c, buffer);
448 if (c == '0' || c == 'n' || c == 'N')
450 else if (c == '1' || c == 'y' || c == 'Y')
457 oplockEnabled_read(char *page, char **start, off_t off,
458 int count, int *eof, void *data)
462 len = sprintf(page, "%d\n", oplockEnabled);
478 oplockEnabled_write(struct file *file, const char __user *buffer,
479 unsigned long count, void *data)
484 rc = get_user(c, buffer);
487 if (c == '0' || c == 'n' || c == 'N')
489 else if (c == '1' || c == 'y' || c == 'Y')
496 quotaEnabled_read(char *page, char **start, off_t off,
497 int count, int *eof, void *data)
501 len = sprintf(page, "%d\n", experimEnabled);
502 /* could also check if quotas are enabled in kernel
518 quotaEnabled_write(struct file *file, const char __user *buffer,
519 unsigned long count, void *data)
524 rc = get_user(c, buffer);
527 if (c == '0' || c == 'n' || c == 'N')
529 else if (c == '1' || c == 'y' || c == 'Y')
536 linuxExtensionsEnabled_read(char *page, char **start, off_t off,
537 int count, int *eof, void *data)
541 len = sprintf(page, "%d\n", linuxExtEnabled);
542 /* could also check if quotas are enabled in kernel
558 linuxExtensionsEnabled_write(struct file *file, const char __user *buffer,
559 unsigned long count, void *data)
564 rc = get_user(c, buffer);
567 if (c == '0' || c == 'n' || c == 'N')
569 else if (c == '1' || c == 'y' || c == 'Y')
577 lookupFlag_read(char *page, char **start, off_t off,
578 int count, int *eof, void *data)
582 len = sprintf(page, "%d\n", lookupCacheEnabled);
598 lookupFlag_write(struct file *file, const char __user *buffer,
599 unsigned long count, void *data)
604 rc = get_user(c, buffer);
607 if (c == '0' || c == 'n' || c == 'N')
608 lookupCacheEnabled = 0;
609 else if (c == '1' || c == 'y' || c == 'Y')
610 lookupCacheEnabled = 1;
615 traceSMB_read(char *page, char **start, off_t off, int count,
616 int *eof, void *data)
620 len = sprintf(page, "%d\n", traceSMB);
636 traceSMB_write(struct file *file, const char __user *buffer,
637 unsigned long count, void *data)
642 rc = get_user(c, buffer);
645 if (c == '0' || c == 'n' || c == 'N')
647 else if (c == '1' || c == 'y' || c == 'Y')
654 multiuser_mount_read(char *page, char **start, off_t off,
655 int count, int *eof, void *data)
659 len = sprintf(page, "%d\n", multiuser_mount);
675 multiuser_mount_write(struct file *file, const char __user *buffer,
676 unsigned long count, void *data)
681 rc = get_user(c, buffer);
684 if (c == '0' || c == 'n' || c == 'N')
686 else if (c == '1' || c == 'y' || c == 'Y')
693 extended_security_read(char *page, char **start, off_t off,
694 int count, int *eof, void *data)
698 len = sprintf(page, "%d\n", extended_security);
714 extended_security_write(struct file *file, const char __user *buffer,
715 unsigned long count, void *data)
720 rc = get_user(c, buffer);
723 if (c == '0' || c == 'n' || c == 'N')
724 extended_security = 0;
725 else if (c == '1' || c == 'y' || c == 'Y')
726 extended_security = 1;
732 ntlmv2_enabled_read(char *page, char **start, off_t off,
733 int count, int *eof, void *data)
737 len = sprintf(page, "%d\n", ntlmv2_support);
753 ntlmv2_enabled_write(struct file *file, const char __user *buffer,
754 unsigned long count, void *data)
759 rc = get_user(c, buffer);
762 if (c == '0' || c == 'n' || c == 'N')
764 else if (c == '1' || c == 'y' || c == 'Y')
771 packet_signing_enabled_read(char *page, char **start, off_t off,
772 int count, int *eof, void *data)
776 len = sprintf(page, "%d\n", sign_CIFS_PDUs);
792 packet_signing_enabled_write(struct file *file, const char __user *buffer,
793 unsigned long count, void *data)
798 rc = get_user(c, buffer);
801 if (c == '0' || c == 'n' || c == 'N')
803 else if (c == '1' || c == 'y' || c == 'Y')