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 "\nLocks: %d HardLinks: %d Symlinks: %d",
274 atomic_read(&tcon->num_locks),
275 atomic_read(&tcon->num_hardlinks),
276 atomic_read(&tcon->num_symlinks));
278 length += item_length;
280 item_length = sprintf(buf, "\nOpens: %d Closes: %d Deletes: %d",
281 atomic_read(&tcon->num_opens),
282 atomic_read(&tcon->num_closes),
283 atomic_read(&tcon->num_deletes));
285 length += item_length;
286 item_length = sprintf(buf, "\nMkdirs: %d Rmdirs: %d",
287 atomic_read(&tcon->num_mkdirs),
288 atomic_read(&tcon->num_rmdirs));
290 length += item_length;
291 item_length = sprintf(buf, "\nRenames: %d T2 Renames %d",
292 atomic_read(&tcon->num_renames),
293 atomic_read(&tcon->num_t2renames));
295 length += item_length;
296 item_length = sprintf(buf, "\nFindFirst: %d FNext %d FClose %d",
297 atomic_read(&tcon->num_ffirst),
298 atomic_read(&tcon->num_fnext),
299 atomic_read(&tcon->num_fclose));
301 length += item_length;
303 read_unlock(&GlobalSMBSeslock);
305 buf += sprintf(buf,"\n");
308 if(offset + count >= length)
310 if(length < offset) {
314 length = length - offset;
323 static struct proc_dir_entry *proc_fs_cifs;
324 read_proc_t cifs_txanchor_read;
325 static read_proc_t cifsFYI_read;
326 static write_proc_t cifsFYI_write;
327 static read_proc_t oplockEnabled_read;
328 static write_proc_t oplockEnabled_write;
329 static read_proc_t lookupFlag_read;
330 static write_proc_t lookupFlag_write;
331 static read_proc_t traceSMB_read;
332 static write_proc_t traceSMB_write;
333 static read_proc_t multiuser_mount_read;
334 static write_proc_t multiuser_mount_write;
335 static read_proc_t extended_security_read;
336 static write_proc_t extended_security_write;
337 static read_proc_t ntlmv2_enabled_read;
338 static write_proc_t ntlmv2_enabled_write;
339 static read_proc_t packet_signing_enabled_read;
340 static write_proc_t packet_signing_enabled_write;
341 static read_proc_t quotaEnabled_read;
342 static write_proc_t quotaEnabled_write;
343 static read_proc_t linuxExtensionsEnabled_read;
344 static write_proc_t linuxExtensionsEnabled_write;
349 struct proc_dir_entry *pde;
351 proc_fs_cifs = proc_mkdir("cifs", proc_root_fs);
352 if (proc_fs_cifs == NULL)
355 proc_fs_cifs->owner = THIS_MODULE;
356 create_proc_read_entry("DebugData", 0, proc_fs_cifs,
357 cifs_debug_data_read, NULL);
359 #ifdef CONFIG_CIFS_STATS
360 create_proc_read_entry("Stats", 0, proc_fs_cifs,
361 cifs_stats_read, NULL);
363 pde = create_proc_read_entry("cifsFYI", 0, proc_fs_cifs,
366 pde->write_proc = cifsFYI_write;
369 create_proc_read_entry("traceSMB", 0, proc_fs_cifs,
370 traceSMB_read, NULL);
372 pde->write_proc = traceSMB_write;
374 pde = create_proc_read_entry("OplockEnabled", 0, proc_fs_cifs,
375 oplockEnabled_read, NULL);
377 pde->write_proc = oplockEnabled_write;
379 pde = create_proc_read_entry("Experimental", 0, proc_fs_cifs,
380 quotaEnabled_read, NULL);
382 pde->write_proc = quotaEnabled_write;
384 pde = create_proc_read_entry("LinuxExtensionsEnabled", 0, proc_fs_cifs,
385 linuxExtensionsEnabled_read, NULL);
387 pde->write_proc = linuxExtensionsEnabled_write;
390 create_proc_read_entry("MultiuserMount", 0, proc_fs_cifs,
391 multiuser_mount_read, NULL);
393 pde->write_proc = multiuser_mount_write;
396 create_proc_read_entry("ExtendedSecurity", 0, proc_fs_cifs,
397 extended_security_read, NULL);
399 pde->write_proc = extended_security_write;
402 create_proc_read_entry("LookupCacheEnabled", 0, proc_fs_cifs,
403 lookupFlag_read, NULL);
405 pde->write_proc = lookupFlag_write;
408 create_proc_read_entry("NTLMV2Enabled", 0, proc_fs_cifs,
409 ntlmv2_enabled_read, NULL);
411 pde->write_proc = ntlmv2_enabled_write;
414 create_proc_read_entry("PacketSigningEnabled", 0, proc_fs_cifs,
415 packet_signing_enabled_read, NULL);
417 pde->write_proc = packet_signing_enabled_write;
421 cifs_proc_clean(void)
423 if (proc_fs_cifs == NULL)
426 remove_proc_entry("DebugData", proc_fs_cifs);
427 remove_proc_entry("cifsFYI", proc_fs_cifs);
428 remove_proc_entry("traceSMB", proc_fs_cifs);
429 #ifdef CONFIG_CIFS_STATS
430 remove_proc_entry("Stats", proc_fs_cifs);
432 remove_proc_entry("MultiuserMount", proc_fs_cifs);
433 remove_proc_entry("OplockEnabled", proc_fs_cifs);
434 remove_proc_entry("NTLMV2Enabled",proc_fs_cifs);
435 remove_proc_entry("ExtendedSecurity",proc_fs_cifs);
436 remove_proc_entry("PacketSigningEnabled",proc_fs_cifs);
437 remove_proc_entry("LinuxExtensionsEnabled",proc_fs_cifs);
438 remove_proc_entry("Experimental",proc_fs_cifs);
439 remove_proc_entry("LookupCacheEnabled",proc_fs_cifs);
440 remove_proc_entry("cifs", proc_root_fs);
444 cifsFYI_read(char *page, char **start, off_t off, int count,
445 int *eof, void *data)
449 len = sprintf(page, "%d\n", cifsFYI);
465 cifsFYI_write(struct file *file, const char __user *buffer,
466 unsigned long count, void *data)
471 rc = get_user(c, buffer);
474 if (c == '0' || c == 'n' || c == 'N')
476 else if (c == '1' || c == 'y' || c == 'Y')
483 oplockEnabled_read(char *page, char **start, off_t off,
484 int count, int *eof, void *data)
488 len = sprintf(page, "%d\n", oplockEnabled);
504 oplockEnabled_write(struct file *file, const char __user *buffer,
505 unsigned long count, void *data)
510 rc = get_user(c, buffer);
513 if (c == '0' || c == 'n' || c == 'N')
515 else if (c == '1' || c == 'y' || c == 'Y')
522 quotaEnabled_read(char *page, char **start, off_t off,
523 int count, int *eof, void *data)
527 len = sprintf(page, "%d\n", experimEnabled);
528 /* could also check if quotas are enabled in kernel
544 quotaEnabled_write(struct file *file, const char __user *buffer,
545 unsigned long count, void *data)
550 rc = get_user(c, buffer);
553 if (c == '0' || c == 'n' || c == 'N')
555 else if (c == '1' || c == 'y' || c == 'Y')
562 linuxExtensionsEnabled_read(char *page, char **start, off_t off,
563 int count, int *eof, void *data)
567 len = sprintf(page, "%d\n", linuxExtEnabled);
568 /* could also check if quotas are enabled in kernel
584 linuxExtensionsEnabled_write(struct file *file, const char __user *buffer,
585 unsigned long count, void *data)
590 rc = get_user(c, buffer);
593 if (c == '0' || c == 'n' || c == 'N')
595 else if (c == '1' || c == 'y' || c == 'Y')
603 lookupFlag_read(char *page, char **start, off_t off,
604 int count, int *eof, void *data)
608 len = sprintf(page, "%d\n", lookupCacheEnabled);
624 lookupFlag_write(struct file *file, const char __user *buffer,
625 unsigned long count, void *data)
630 rc = get_user(c, buffer);
633 if (c == '0' || c == 'n' || c == 'N')
634 lookupCacheEnabled = 0;
635 else if (c == '1' || c == 'y' || c == 'Y')
636 lookupCacheEnabled = 1;
641 traceSMB_read(char *page, char **start, off_t off, int count,
642 int *eof, void *data)
646 len = sprintf(page, "%d\n", traceSMB);
662 traceSMB_write(struct file *file, const char __user *buffer,
663 unsigned long count, void *data)
668 rc = get_user(c, buffer);
671 if (c == '0' || c == 'n' || c == 'N')
673 else if (c == '1' || c == 'y' || c == 'Y')
680 multiuser_mount_read(char *page, char **start, off_t off,
681 int count, int *eof, void *data)
685 len = sprintf(page, "%d\n", multiuser_mount);
701 multiuser_mount_write(struct file *file, const char __user *buffer,
702 unsigned long count, void *data)
707 rc = get_user(c, buffer);
710 if (c == '0' || c == 'n' || c == 'N')
712 else if (c == '1' || c == 'y' || c == 'Y')
719 extended_security_read(char *page, char **start, off_t off,
720 int count, int *eof, void *data)
724 len = sprintf(page, "%d\n", extended_security);
740 extended_security_write(struct file *file, const char __user *buffer,
741 unsigned long count, void *data)
746 rc = get_user(c, buffer);
749 if (c == '0' || c == 'n' || c == 'N')
750 extended_security = 0;
751 else if (c == '1' || c == 'y' || c == 'Y')
752 extended_security = 1;
758 ntlmv2_enabled_read(char *page, char **start, off_t off,
759 int count, int *eof, void *data)
763 len = sprintf(page, "%d\n", ntlmv2_support);
779 ntlmv2_enabled_write(struct file *file, const char __user *buffer,
780 unsigned long count, void *data)
785 rc = get_user(c, buffer);
788 if (c == '0' || c == 'n' || c == 'N')
790 else if (c == '1' || c == 'y' || c == 'Y')
797 packet_signing_enabled_read(char *page, char **start, off_t off,
798 int count, int *eof, void *data)
802 len = sprintf(page, "%d\n", sign_CIFS_PDUs);
818 packet_signing_enabled_write(struct file *file, const char __user *buffer,
819 unsigned long count, void *data)
824 rc = get_user(c, buffer);
827 if (c == '0' || c == 'n' || c == 'N')
829 else if (c == '1' || c == 'y' || c == 'Y')