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\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);
92 if((ses->serverDomain == NULL) || (ses->serverOS == NULL) ||
93 (ses->serverNOS == NULL)) {
94 buf += sprintf("\nentry for %s not fully displayed\n\t",
100 "\n%d) Name: %s Domain: %s Mounts: %d ServerOS: %s \n\tServerNOS: %s\tCapabilities: 0x%x\n\tSMB session status: %d\t",
101 i, ses->serverName, ses->serverDomain,
102 atomic_read(&ses->inUse),
103 ses->serverOS, ses->serverNOS,
104 ses->capabilities,ses->status);
108 buf += sprintf(buf, "TCP status: %d\n\tLocal Users To Server: %d SecMode: 0x%x Req Active: %d",
109 ses->server->tcpStatus,
110 atomic_read(&ses->server->socketUseCount),
111 ses->server->secMode,
112 atomic_read(&ses->server->inFlight));
114 length = sprintf(buf, "\nMIDs:\n");
117 spin_lock(&GlobalMid_Lock);
118 list_for_each(tmp1, &ses->server->pending_mid_q) {
119 mid_entry = list_entry(tmp1, struct
123 length = sprintf(buf,"State: %d com: %d pid: %d tsk: %p mid %d\n",
125 (int)mid_entry->command,
132 spin_unlock(&GlobalMid_Lock);
136 read_unlock(&GlobalSMBSeslock);
140 length = sprintf(buf, "Shares:");
144 read_lock(&GlobalSMBSeslock);
145 list_for_each(tmp, &GlobalTreeConnectionList) {
148 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
149 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
152 "\n%d) %s Uses: %d Type: %s Characteristics: 0x%x Attributes: 0x%x\nPathComponentMax: %d Status: %d",
154 atomic_read(&tcon->useCount),
155 tcon->nativeFileSystem,
156 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
157 le32_to_cpu(tcon->fsAttrInfo.Attributes),
158 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
161 if (dev_type == FILE_DEVICE_DISK)
162 length = sprintf(buf, " type: DISK ");
163 else if (dev_type == FILE_DEVICE_CD_ROM)
164 length = sprintf(buf, " type: CDROM ");
167 sprintf(buf, " type: %d ", dev_type);
169 if(tcon->tidStatus == CifsNeedReconnect) {
170 buf += sprintf(buf, "\tDISCONNECTED ");
174 read_unlock(&GlobalSMBSeslock);
176 length = sprintf(buf, "\n");
179 /* BB add code to dump additional info such as TCP session info now */
180 /* Now calculate total size of returned data */
181 length = buf - original_buf;
183 if(offset + count >= length)
185 if(length < offset) {
189 length = length - offset;
197 #ifdef CONFIG_CIFS_STATS
199 cifs_stats_read(char *buf, char **beginBuffer, off_t offset,
200 int count, int *eof, void *data)
202 int item_length,i,length;
203 struct list_head *tmp;
204 struct cifsTconInfo *tcon;
206 *beginBuffer = buf + offset;
208 length = sprintf(buf,
209 "Resources in use\nCIFS Session: %d\n",
210 sesInfoAllocCount.counter);
213 sprintf(buf,"Share (unique mount targets): %d\n",
214 tconInfoAllocCount.counter);
215 length += item_length;
218 sprintf(buf,"SMB Request/Response Buffer: %d Pool size: %d\n",
219 bufAllocCount.counter,
220 cifs_min_rcv + tcpSesAllocCount.counter);
221 length += item_length;
224 sprintf(buf,"SMB Small Req/Resp Buffer: %d Pool size: %d\n",
225 smBufAllocCount.counter,cifs_min_small);
226 length += item_length;
229 sprintf(buf,"Operations (MIDs): %d\n",
231 length += item_length;
233 item_length = sprintf(buf,
234 "\n%d session %d share reconnects\n",
235 tcpSesReconnectCount.counter,tconInfoReconnectCount.counter);
236 length += item_length;
239 item_length = sprintf(buf,
240 "Total vfs operations: %d maximum at one time: %d\n",
241 GlobalCurrentXid,GlobalMaxActiveXid);
242 length += item_length;
246 read_lock(&GlobalSMBSeslock);
247 list_for_each(tmp, &GlobalTreeConnectionList) {
249 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
250 item_length = sprintf(buf,"\n%d) %s",i, tcon->treeName);
252 length += item_length;
253 if(tcon->tidStatus == CifsNeedReconnect) {
254 buf += sprintf(buf, "\tDISCONNECTED ");
257 item_length = sprintf(buf,"\nSMBs: %d Oplock Breaks: %d",
258 atomic_read(&tcon->num_smbs_sent),
259 atomic_read(&tcon->num_oplock_brks));
261 length += item_length;
262 item_length = sprintf(buf,"\nReads: %d Bytes %lld",
263 atomic_read(&tcon->num_reads),
264 (long long)(tcon->bytes_read));
266 length += item_length;
267 item_length = sprintf(buf,"\nWrites: %d Bytes: %lld",
268 atomic_read(&tcon->num_writes),
269 (long long)(tcon->bytes_written));
271 length += item_length;
272 item_length = sprintf(buf,
273 "\nOpens: %d Deletes: %d\nMkdirs: %d Rmdirs: %d",
274 atomic_read(&tcon->num_opens),
275 atomic_read(&tcon->num_deletes),
276 atomic_read(&tcon->num_mkdirs),
277 atomic_read(&tcon->num_rmdirs));
279 length += item_length;
280 item_length = sprintf(buf,
281 "\nRenames: %d T2 Renames %d",
282 atomic_read(&tcon->num_renames),
283 atomic_read(&tcon->num_t2renames));
285 length += item_length;
287 read_unlock(&GlobalSMBSeslock);
289 buf += sprintf(buf,"\n");
292 if(offset + count >= length)
294 if(length < offset) {
298 length = length - offset;
307 static struct proc_dir_entry *proc_fs_cifs;
308 read_proc_t cifs_txanchor_read;
309 static read_proc_t cifsFYI_read;
310 static write_proc_t cifsFYI_write;
311 static read_proc_t oplockEnabled_read;
312 static write_proc_t oplockEnabled_write;
313 static read_proc_t lookupFlag_read;
314 static write_proc_t lookupFlag_write;
315 static read_proc_t traceSMB_read;
316 static write_proc_t traceSMB_write;
317 static read_proc_t multiuser_mount_read;
318 static write_proc_t multiuser_mount_write;
319 static read_proc_t extended_security_read;
320 static write_proc_t extended_security_write;
321 static read_proc_t ntlmv2_enabled_read;
322 static write_proc_t ntlmv2_enabled_write;
323 static read_proc_t packet_signing_enabled_read;
324 static write_proc_t packet_signing_enabled_write;
325 static read_proc_t quotaEnabled_read;
326 static write_proc_t quotaEnabled_write;
327 static read_proc_t linuxExtensionsEnabled_read;
328 static write_proc_t linuxExtensionsEnabled_write;
333 struct proc_dir_entry *pde;
335 proc_fs_cifs = proc_mkdir("cifs", proc_root_fs);
336 if (proc_fs_cifs == NULL)
339 proc_fs_cifs->owner = THIS_MODULE;
340 create_proc_read_entry("DebugData", 0, proc_fs_cifs,
341 cifs_debug_data_read, NULL);
343 #ifdef CONFIG_CIFS_STATS
344 create_proc_read_entry("Stats", 0, proc_fs_cifs,
345 cifs_stats_read, NULL);
347 pde = create_proc_read_entry("cifsFYI", 0, proc_fs_cifs,
350 pde->write_proc = cifsFYI_write;
353 create_proc_read_entry("traceSMB", 0, proc_fs_cifs,
354 traceSMB_read, NULL);
356 pde->write_proc = traceSMB_write;
358 pde = create_proc_read_entry("OplockEnabled", 0, proc_fs_cifs,
359 oplockEnabled_read, NULL);
361 pde->write_proc = oplockEnabled_write;
363 pde = create_proc_read_entry("ReenableOldCifsReaddirCode", 0, proc_fs_cifs,
364 quotaEnabled_read, NULL);
366 pde->write_proc = quotaEnabled_write;
368 pde = create_proc_read_entry("LinuxExtensionsEnabled", 0, proc_fs_cifs,
369 linuxExtensionsEnabled_read, NULL);
371 pde->write_proc = linuxExtensionsEnabled_write;
374 create_proc_read_entry("MultiuserMount", 0, proc_fs_cifs,
375 multiuser_mount_read, NULL);
377 pde->write_proc = multiuser_mount_write;
380 create_proc_read_entry("ExtendedSecurity", 0, proc_fs_cifs,
381 extended_security_read, NULL);
383 pde->write_proc = extended_security_write;
386 create_proc_read_entry("LookupCacheEnabled", 0, proc_fs_cifs,
387 lookupFlag_read, NULL);
389 pde->write_proc = lookupFlag_write;
392 create_proc_read_entry("NTLMV2Enabled", 0, proc_fs_cifs,
393 ntlmv2_enabled_read, NULL);
395 pde->write_proc = ntlmv2_enabled_write;
398 create_proc_read_entry("PacketSigningEnabled", 0, proc_fs_cifs,
399 packet_signing_enabled_read, NULL);
401 pde->write_proc = packet_signing_enabled_write;
405 cifs_proc_clean(void)
407 if (proc_fs_cifs == NULL)
410 remove_proc_entry("DebugData", proc_fs_cifs);
411 remove_proc_entry("cifsFYI", proc_fs_cifs);
412 remove_proc_entry("traceSMB", proc_fs_cifs);
413 #ifdef CONFIG_CIFS_STATS
414 remove_proc_entry("Stats", proc_fs_cifs);
416 remove_proc_entry("MultiuserMount", proc_fs_cifs);
417 remove_proc_entry("OplockEnabled", proc_fs_cifs);
418 remove_proc_entry("NTLMV2Enabled",proc_fs_cifs);
419 remove_proc_entry("ExtendedSecurity",proc_fs_cifs);
420 remove_proc_entry("PacketSigningEnabled",proc_fs_cifs);
421 remove_proc_entry("LinuxExtensionsEnabled",proc_fs_cifs);
422 remove_proc_entry("ReenableOldCifsReaddirCode",proc_fs_cifs);
423 remove_proc_entry("LookupCacheEnabled",proc_fs_cifs);
424 remove_proc_entry("cifs", proc_root_fs);
428 cifsFYI_read(char *page, char **start, off_t off, int count,
429 int *eof, void *data)
433 len = sprintf(page, "%d\n", cifsFYI);
449 cifsFYI_write(struct file *file, const char __user *buffer,
450 unsigned long count, void *data)
455 rc = get_user(c, buffer);
458 if (c == '0' || c == 'n' || c == 'N')
460 else if (c == '1' || c == 'y' || c == 'Y')
467 oplockEnabled_read(char *page, char **start, off_t off,
468 int count, int *eof, void *data)
472 len = sprintf(page, "%d\n", oplockEnabled);
488 oplockEnabled_write(struct file *file, const char __user *buffer,
489 unsigned long count, void *data)
494 rc = get_user(c, buffer);
497 if (c == '0' || c == 'n' || c == 'N')
499 else if (c == '1' || c == 'y' || c == 'Y')
506 quotaEnabled_read(char *page, char **start, off_t off,
507 int count, int *eof, void *data)
511 len = sprintf(page, "%d\n", experimEnabled);
512 /* could also check if quotas are enabled in kernel
528 quotaEnabled_write(struct file *file, const char __user *buffer,
529 unsigned long count, void *data)
534 rc = get_user(c, buffer);
537 if (c == '0' || c == 'n' || c == 'N')
539 else if (c == '1' || c == 'y' || c == 'Y')
546 linuxExtensionsEnabled_read(char *page, char **start, off_t off,
547 int count, int *eof, void *data)
551 len = sprintf(page, "%d\n", linuxExtEnabled);
552 /* could also check if quotas are enabled in kernel
568 linuxExtensionsEnabled_write(struct file *file, const char __user *buffer,
569 unsigned long count, void *data)
574 rc = get_user(c, buffer);
577 if (c == '0' || c == 'n' || c == 'N')
579 else if (c == '1' || c == 'y' || c == 'Y')
587 lookupFlag_read(char *page, char **start, off_t off,
588 int count, int *eof, void *data)
592 len = sprintf(page, "%d\n", lookupCacheEnabled);
608 lookupFlag_write(struct file *file, const char __user *buffer,
609 unsigned long count, void *data)
614 rc = get_user(c, buffer);
617 if (c == '0' || c == 'n' || c == 'N')
618 lookupCacheEnabled = 0;
619 else if (c == '1' || c == 'y' || c == 'Y')
620 lookupCacheEnabled = 1;
625 traceSMB_read(char *page, char **start, off_t off, int count,
626 int *eof, void *data)
630 len = sprintf(page, "%d\n", traceSMB);
646 traceSMB_write(struct file *file, const char __user *buffer,
647 unsigned long count, void *data)
652 rc = get_user(c, buffer);
655 if (c == '0' || c == 'n' || c == 'N')
657 else if (c == '1' || c == 'y' || c == 'Y')
664 multiuser_mount_read(char *page, char **start, off_t off,
665 int count, int *eof, void *data)
669 len = sprintf(page, "%d\n", multiuser_mount);
685 multiuser_mount_write(struct file *file, const char __user *buffer,
686 unsigned long count, void *data)
691 rc = get_user(c, buffer);
694 if (c == '0' || c == 'n' || c == 'N')
696 else if (c == '1' || c == 'y' || c == 'Y')
703 extended_security_read(char *page, char **start, off_t off,
704 int count, int *eof, void *data)
708 len = sprintf(page, "%d\n", extended_security);
724 extended_security_write(struct file *file, const char __user *buffer,
725 unsigned long count, void *data)
730 rc = get_user(c, buffer);
733 if (c == '0' || c == 'n' || c == 'N')
734 extended_security = 0;
735 else if (c == '1' || c == 'y' || c == 'Y')
736 extended_security = 1;
742 ntlmv2_enabled_read(char *page, char **start, off_t off,
743 int count, int *eof, void *data)
747 len = sprintf(page, "%d\n", ntlmv2_support);
763 ntlmv2_enabled_write(struct file *file, const char __user *buffer,
764 unsigned long count, void *data)
769 rc = get_user(c, buffer);
772 if (c == '0' || c == 'n' || c == 'N')
774 else if (c == '1' || c == 'y' || c == 'Y')
781 packet_signing_enabled_read(char *page, char **start, off_t off,
782 int count, int *eof, void *data)
786 len = sprintf(page, "%d\n", sign_CIFS_PDUs);
802 packet_signing_enabled_write(struct file *file, const char __user *buffer,
803 unsigned long count, void *data)
808 rc = get_user(c, buffer);
811 if (c == '0' || c == 'n' || c == 'N')
813 else if (c == '1' || c == 'y' || c == 'Y')