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",mid_entry->midState,mid_entry->command,mid_entry->pid,mid_entry->tsk,mid_entry->mid);
118 spin_unlock(&GlobalMid_Lock);
122 read_unlock(&GlobalSMBSeslock);
126 length = sprintf(buf, "Shares:");
130 read_lock(&GlobalSMBSeslock);
131 list_for_each(tmp, &GlobalTreeConnectionList) {
134 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
135 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
138 "\n%d) %s Uses: %d Type: %s Characteristics: 0x%x Attributes: 0x%x\nPathComponentMax: %d Status: %d",
140 atomic_read(&tcon->useCount),
141 tcon->nativeFileSystem,
142 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
143 le32_to_cpu(tcon->fsAttrInfo.Attributes),
144 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
147 if (dev_type == FILE_DEVICE_DISK)
148 length = sprintf(buf, " type: DISK ");
149 else if (dev_type == FILE_DEVICE_CD_ROM)
150 length = sprintf(buf, " type: CDROM ");
153 sprintf(buf, " type: %d ", dev_type);
155 if(tcon->tidStatus == CifsNeedReconnect) {
156 buf += sprintf(buf, "\tDISCONNECTED ");
160 read_unlock(&GlobalSMBSeslock);
162 length = sprintf(buf, "\n");
165 /* BB add code to dump additional info such as TCP session info now */
166 /* Now calculate total size of returned data */
167 length = buf - original_buf;
169 if(offset + count >= length)
171 if(length < offset) {
175 length = length - offset;
183 #ifdef CONFIG_CIFS_STATS
185 cifs_stats_read(char *buf, char **beginBuffer, off_t offset,
186 int count, int *eof, void *data)
188 int item_length,i,length;
189 struct list_head *tmp;
190 struct cifsTconInfo *tcon;
192 *beginBuffer = buf + offset;
194 length = sprintf(buf,
195 "Resources in use\nCIFS Session: %d\n",
196 sesInfoAllocCount.counter);
199 sprintf(buf,"Share (unique mount targets): %d\n",
200 tconInfoAllocCount.counter);
201 length += item_length;
204 sprintf(buf,"SMB Request/Response Buffer: %d Pool size: %d\n",
205 bufAllocCount.counter,cifs_min_rcv + tcpSesAllocCount.counter);
206 length += item_length;
209 sprintf(buf,"SMB Small Req/Resp Buffer: %d Pool size: %d\n",
210 smBufAllocCount.counter,cifs_min_small);
211 length += item_length;
214 sprintf(buf,"Operations (MIDs): %d\n",
216 length += item_length;
218 item_length = sprintf(buf,
219 "\n%d session %d share reconnects\n",
220 tcpSesReconnectCount.counter,tconInfoReconnectCount.counter);
221 length += item_length;
224 item_length = sprintf(buf,
225 "Total vfs operations: %d maximum at one time: %d\n",
226 GlobalCurrentXid,GlobalMaxActiveXid);
227 length += item_length;
231 read_lock(&GlobalSMBSeslock);
232 list_for_each(tmp, &GlobalTreeConnectionList) {
234 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
235 item_length = sprintf(buf,"\n%d) %s",i, tcon->treeName);
237 length += item_length;
238 if(tcon->tidStatus == CifsNeedReconnect) {
239 buf += sprintf(buf, "\tDISCONNECTED ");
242 item_length = sprintf(buf,"\nSMBs: %d Oplock Breaks: %d",
243 atomic_read(&tcon->num_smbs_sent),
244 atomic_read(&tcon->num_oplock_brks));
246 length += item_length;
247 item_length = sprintf(buf,"\nReads: %d Bytes %lld",
248 atomic_read(&tcon->num_reads),
249 (long long)(tcon->bytes_read));
251 length += item_length;
252 item_length = sprintf(buf,"\nWrites: %d Bytes: %lld",
253 atomic_read(&tcon->num_writes),
254 (long long)(tcon->bytes_written));
256 length += item_length;
257 item_length = sprintf(buf,
258 "\nOpens: %d Deletes: %d\nMkdirs: %d Rmdirs: %d",
259 atomic_read(&tcon->num_opens),
260 atomic_read(&tcon->num_deletes),
261 atomic_read(&tcon->num_mkdirs),
262 atomic_read(&tcon->num_rmdirs));
264 length += item_length;
265 item_length = sprintf(buf,
266 "\nRenames: %d T2 Renames %d",
267 atomic_read(&tcon->num_renames),
268 atomic_read(&tcon->num_t2renames));
270 length += item_length;
272 read_unlock(&GlobalSMBSeslock);
274 buf += sprintf(buf,"\n");
277 if(offset + count >= length)
279 if(length < offset) {
283 length = length - offset;
292 static struct proc_dir_entry *proc_fs_cifs;
293 read_proc_t cifs_txanchor_read;
294 static read_proc_t cifsFYI_read;
295 static write_proc_t cifsFYI_write;
296 static read_proc_t oplockEnabled_read;
297 static write_proc_t oplockEnabled_write;
298 static read_proc_t lookupFlag_read;
299 static write_proc_t lookupFlag_write;
300 static read_proc_t traceSMB_read;
301 static write_proc_t traceSMB_write;
302 static read_proc_t multiuser_mount_read;
303 static write_proc_t multiuser_mount_write;
304 static read_proc_t extended_security_read;
305 static write_proc_t extended_security_write;
306 static read_proc_t ntlmv2_enabled_read;
307 static write_proc_t ntlmv2_enabled_write;
308 static read_proc_t packet_signing_enabled_read;
309 static write_proc_t packet_signing_enabled_write;
310 static read_proc_t quotaEnabled_read;
311 static write_proc_t quotaEnabled_write;
312 static read_proc_t linuxExtensionsEnabled_read;
313 static write_proc_t linuxExtensionsEnabled_write;
318 struct proc_dir_entry *pde;
320 proc_fs_cifs = proc_mkdir("cifs", proc_root_fs);
321 if (proc_fs_cifs == NULL)
324 proc_fs_cifs->owner = THIS_MODULE;
325 create_proc_read_entry("DebugData", 0, proc_fs_cifs,
326 cifs_debug_data_read, NULL);
328 #ifdef CONFIG_CIFS_STATS
329 create_proc_read_entry("Stats", 0, proc_fs_cifs,
330 cifs_stats_read, NULL);
332 pde = create_proc_read_entry("cifsFYI", 0, proc_fs_cifs,
335 pde->write_proc = cifsFYI_write;
338 create_proc_read_entry("traceSMB", 0, proc_fs_cifs,
339 traceSMB_read, NULL);
341 pde->write_proc = traceSMB_write;
343 pde = create_proc_read_entry("OplockEnabled", 0, proc_fs_cifs,
344 oplockEnabled_read, NULL);
346 pde->write_proc = oplockEnabled_write;
348 pde = create_proc_read_entry("ReenableOldCifsReaddirCode", 0, proc_fs_cifs,
349 quotaEnabled_read, NULL);
351 pde->write_proc = quotaEnabled_write;
353 pde = create_proc_read_entry("LinuxExtensionsEnabled", 0, proc_fs_cifs,
354 linuxExtensionsEnabled_read, NULL);
356 pde->write_proc = linuxExtensionsEnabled_write;
359 create_proc_read_entry("MultiuserMount", 0, proc_fs_cifs,
360 multiuser_mount_read, NULL);
362 pde->write_proc = multiuser_mount_write;
365 create_proc_read_entry("ExtendedSecurity", 0, proc_fs_cifs,
366 extended_security_read, NULL);
368 pde->write_proc = extended_security_write;
371 create_proc_read_entry("LookupCacheEnabled", 0, proc_fs_cifs,
372 lookupFlag_read, NULL);
374 pde->write_proc = lookupFlag_write;
377 create_proc_read_entry("NTLMV2Enabled", 0, proc_fs_cifs,
378 ntlmv2_enabled_read, NULL);
380 pde->write_proc = ntlmv2_enabled_write;
383 create_proc_read_entry("PacketSigningEnabled", 0, proc_fs_cifs,
384 packet_signing_enabled_read, NULL);
386 pde->write_proc = packet_signing_enabled_write;
390 cifs_proc_clean(void)
392 if (proc_fs_cifs == NULL)
395 remove_proc_entry("DebugData", proc_fs_cifs);
396 remove_proc_entry("cifsFYI", proc_fs_cifs);
397 remove_proc_entry("traceSMB", proc_fs_cifs);
398 #ifdef CONFIG_CIFS_STATS
399 remove_proc_entry("Stats", proc_fs_cifs);
401 remove_proc_entry("MultiuserMount", proc_fs_cifs);
402 remove_proc_entry("OplockEnabled", proc_fs_cifs);
403 remove_proc_entry("NTLMV2Enabled",proc_fs_cifs);
404 remove_proc_entry("ExtendedSecurity",proc_fs_cifs);
405 remove_proc_entry("PacketSigningEnabled",proc_fs_cifs);
406 remove_proc_entry("LinuxExtensionsEnabled",proc_fs_cifs);
407 remove_proc_entry("ReenableOldCifsReaddirCode",proc_fs_cifs);
408 remove_proc_entry("LookupCacheEnabled",proc_fs_cifs);
409 remove_proc_entry("cifs", proc_root_fs);
413 cifsFYI_read(char *page, char **start, off_t off, int count,
414 int *eof, void *data)
418 len = sprintf(page, "%d\n", cifsFYI);
434 cifsFYI_write(struct file *file, const char __user *buffer,
435 unsigned long count, void *data)
440 rc = get_user(c, buffer);
443 if (c == '0' || c == 'n' || c == 'N')
445 else if (c == '1' || c == 'y' || c == 'Y')
452 oplockEnabled_read(char *page, char **start, off_t off,
453 int count, int *eof, void *data)
457 len = sprintf(page, "%d\n", oplockEnabled);
473 oplockEnabled_write(struct file *file, const char __user *buffer,
474 unsigned long count, void *data)
479 rc = get_user(c, buffer);
482 if (c == '0' || c == 'n' || c == 'N')
484 else if (c == '1' || c == 'y' || c == 'Y')
491 quotaEnabled_read(char *page, char **start, off_t off,
492 int count, int *eof, void *data)
496 len = sprintf(page, "%d\n", experimEnabled);
497 /* could also check if quotas are enabled in kernel
513 quotaEnabled_write(struct file *file, const char __user *buffer,
514 unsigned long count, void *data)
519 rc = get_user(c, buffer);
522 if (c == '0' || c == 'n' || c == 'N')
524 else if (c == '1' || c == 'y' || c == 'Y')
531 linuxExtensionsEnabled_read(char *page, char **start, off_t off,
532 int count, int *eof, void *data)
536 len = sprintf(page, "%d\n", linuxExtEnabled);
537 /* could also check if quotas are enabled in kernel
553 linuxExtensionsEnabled_write(struct file *file, const char __user *buffer,
554 unsigned long count, void *data)
559 rc = get_user(c, buffer);
562 if (c == '0' || c == 'n' || c == 'N')
564 else if (c == '1' || c == 'y' || c == 'Y')
572 lookupFlag_read(char *page, char **start, off_t off,
573 int count, int *eof, void *data)
577 len = sprintf(page, "%d\n", lookupCacheEnabled);
593 lookupFlag_write(struct file *file, const char __user *buffer,
594 unsigned long count, void *data)
599 rc = get_user(c, buffer);
602 if (c == '0' || c == 'n' || c == 'N')
603 lookupCacheEnabled = 0;
604 else if (c == '1' || c == 'y' || c == 'Y')
605 lookupCacheEnabled = 1;
610 traceSMB_read(char *page, char **start, off_t off, int count,
611 int *eof, void *data)
615 len = sprintf(page, "%d\n", traceSMB);
631 traceSMB_write(struct file *file, const char __user *buffer,
632 unsigned long count, void *data)
637 rc = get_user(c, buffer);
640 if (c == '0' || c == 'n' || c == 'N')
642 else if (c == '1' || c == 'y' || c == 'Y')
649 multiuser_mount_read(char *page, char **start, off_t off,
650 int count, int *eof, void *data)
654 len = sprintf(page, "%d\n", multiuser_mount);
670 multiuser_mount_write(struct file *file, const char __user *buffer,
671 unsigned long count, void *data)
676 rc = get_user(c, buffer);
679 if (c == '0' || c == 'n' || c == 'N')
681 else if (c == '1' || c == 'y' || c == 'Y')
688 extended_security_read(char *page, char **start, off_t off,
689 int count, int *eof, void *data)
693 len = sprintf(page, "%d\n", extended_security);
709 extended_security_write(struct file *file, const char __user *buffer,
710 unsigned long count, void *data)
715 rc = get_user(c, buffer);
718 if (c == '0' || c == 'n' || c == 'N')
719 extended_security = 0;
720 else if (c == '1' || c == 'y' || c == 'Y')
721 extended_security = 1;
727 ntlmv2_enabled_read(char *page, char **start, off_t off,
728 int count, int *eof, void *data)
732 len = sprintf(page, "%d\n", ntlmv2_support);
748 ntlmv2_enabled_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')
759 else if (c == '1' || c == 'y' || c == 'Y')
766 packet_signing_enabled_read(char *page, char **start, off_t off,
767 int count, int *eof, void *data)
771 len = sprintf(page, "%d\n", sign_CIFS_PDUs);
787 packet_signing_enabled_write(struct file *file, const char __user *buffer,
788 unsigned long count, void *data)
793 rc = get_user(c, buffer);
796 if (c == '0' || c == 'n' || c == 'N')
798 else if (c == '1' || c == 'y' || c == 'Y')