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,"Active VFS Requests: %d\n", GlobalTotalActiveXid);
86 length = sprintf(buf, "Servers:");
90 read_lock(&GlobalSMBSeslock);
91 list_for_each(tmp, &GlobalSMBSessionList) {
93 ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
94 if((ses->serverDomain == NULL) || (ses->serverOS == NULL) ||
95 (ses->serverNOS == NULL)) {
96 buf += sprintf("\nentry for %s not fully displayed\n\t",
102 "\n%d) Name: %s Domain: %s Mounts: %d OS: %s \n\tNOS: %s\tCapability: 0x%x\n\tSMB session status: %d\t",
103 i, ses->serverName, ses->serverDomain,
104 atomic_read(&ses->inUse),
105 ses->serverOS, ses->serverNOS,
106 ses->capabilities,ses->status);
110 buf += sprintf(buf, "TCP status: %d\n\tLocal Users To Server: %d SecMode: 0x%x Req On Wire: %d",
111 ses->server->tcpStatus,
112 atomic_read(&ses->server->socketUseCount),
113 ses->server->secMode,
114 atomic_read(&ses->server->inFlight));
116 #ifdef CONFIG_CIFS_STATS2
117 buf += sprintf(buf, " In Send: %d In MaxReq Wait: %d",
118 atomic_read(&ses->server->inSend),
119 atomic_read(&ses->server->num_waiters));
122 length = sprintf(buf, "\nMIDs:\n");
125 spin_lock(&GlobalMid_Lock);
126 list_for_each(tmp1, &ses->server->pending_mid_q) {
127 mid_entry = list_entry(tmp1, struct
131 length = sprintf(buf,"State: %d com: %d pid: %d tsk: %p mid %d\n",
133 (int)mid_entry->command,
140 spin_unlock(&GlobalMid_Lock);
144 read_unlock(&GlobalSMBSeslock);
148 length = sprintf(buf, "Shares:");
152 read_lock(&GlobalSMBSeslock);
153 list_for_each(tmp, &GlobalTreeConnectionList) {
156 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
157 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
160 "\n%d) %s Uses: %d Type: %s DevInfo: 0x%x Attributes: 0x%x\nPathComponentMax: %d Status: %d",
162 atomic_read(&tcon->useCount),
163 tcon->nativeFileSystem,
164 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
165 le32_to_cpu(tcon->fsAttrInfo.Attributes),
166 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
169 if (dev_type == FILE_DEVICE_DISK)
170 length = sprintf(buf, " type: DISK ");
171 else if (dev_type == FILE_DEVICE_CD_ROM)
172 length = sprintf(buf, " type: CDROM ");
175 sprintf(buf, " type: %d ", dev_type);
177 if(tcon->tidStatus == CifsNeedReconnect) {
178 buf += sprintf(buf, "\tDISCONNECTED ");
182 read_unlock(&GlobalSMBSeslock);
184 length = sprintf(buf, "\n");
187 /* BB add code to dump additional info such as TCP session info now */
188 /* Now calculate total size of returned data */
189 length = buf - original_buf;
191 if(offset + count >= length)
193 if(length < offset) {
197 length = length - offset;
205 #ifdef CONFIG_CIFS_STATS
208 cifs_stats_write(struct file *file, const char __user *buffer,
209 unsigned long count, void *data)
213 struct list_head *tmp;
214 struct cifsTconInfo *tcon;
216 rc = get_user(c, buffer);
220 if (c == '1' || c == 'y' || c == 'Y') {
221 read_lock(&GlobalSMBSeslock);
222 list_for_each(tmp, &GlobalTreeConnectionList) {
223 tcon = list_entry(tmp, struct cifsTconInfo,
225 atomic_set(&tcon->num_smbs_sent, 0);
226 atomic_set(&tcon->num_writes, 0);
227 atomic_set(&tcon->num_reads, 0);
228 atomic_set(&tcon->num_oplock_brks, 0);
229 atomic_set(&tcon->num_opens, 0);
230 atomic_set(&tcon->num_closes, 0);
231 atomic_set(&tcon->num_deletes, 0);
232 atomic_set(&tcon->num_mkdirs, 0);
233 atomic_set(&tcon->num_rmdirs, 0);
234 atomic_set(&tcon->num_renames, 0);
235 atomic_set(&tcon->num_t2renames, 0);
236 atomic_set(&tcon->num_ffirst, 0);
237 atomic_set(&tcon->num_fnext, 0);
238 atomic_set(&tcon->num_fclose, 0);
239 atomic_set(&tcon->num_hardlinks, 0);
240 atomic_set(&tcon->num_symlinks, 0);
241 atomic_set(&tcon->num_locks, 0);
243 read_unlock(&GlobalSMBSeslock);
250 cifs_stats_read(char *buf, char **beginBuffer, off_t offset,
251 int count, int *eof, void *data)
253 int item_length,i,length;
254 struct list_head *tmp;
255 struct cifsTconInfo *tcon;
257 *beginBuffer = buf + offset;
259 length = sprintf(buf,
260 "Resources in use\nCIFS Session: %d\n",
261 sesInfoAllocCount.counter);
264 sprintf(buf,"Share (unique mount targets): %d\n",
265 tconInfoAllocCount.counter);
266 length += item_length;
269 sprintf(buf,"SMB Request/Response Buffer: %d Pool size: %d\n",
270 bufAllocCount.counter,
271 cifs_min_rcv + tcpSesAllocCount.counter);
272 length += item_length;
275 sprintf(buf,"SMB Small Req/Resp Buffer: %d Pool size: %d\n",
276 smBufAllocCount.counter,cifs_min_small);
277 length += item_length;
280 sprintf(buf,"Operations (MIDs): %d\n",
282 length += item_length;
284 item_length = sprintf(buf,
285 "\n%d session %d share reconnects\n",
286 tcpSesReconnectCount.counter,tconInfoReconnectCount.counter);
287 length += item_length;
290 item_length = sprintf(buf,
291 "Total vfs operations: %d maximum at one time: %d\n",
292 GlobalCurrentXid,GlobalMaxActiveXid);
293 length += item_length;
297 read_lock(&GlobalSMBSeslock);
298 list_for_each(tmp, &GlobalTreeConnectionList) {
300 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
301 item_length = sprintf(buf,"\n%d) %s",i, tcon->treeName);
303 length += item_length;
304 if(tcon->tidStatus == CifsNeedReconnect) {
305 buf += sprintf(buf, "\tDISCONNECTED ");
308 item_length = sprintf(buf, "\nSMBs: %d Oplock Breaks: %d",
309 atomic_read(&tcon->num_smbs_sent),
310 atomic_read(&tcon->num_oplock_brks));
312 length += item_length;
313 item_length = sprintf(buf, "\nReads: %d Bytes: %lld",
314 atomic_read(&tcon->num_reads),
315 (long long)(tcon->bytes_read));
317 length += item_length;
318 item_length = sprintf(buf, "\nWrites: %d Bytes: %lld",
319 atomic_read(&tcon->num_writes),
320 (long long)(tcon->bytes_written));
322 length += item_length;
323 item_length = sprintf(buf,
324 "\nLocks: %d HardLinks: %d Symlinks: %d",
325 atomic_read(&tcon->num_locks),
326 atomic_read(&tcon->num_hardlinks),
327 atomic_read(&tcon->num_symlinks));
329 length += item_length;
331 item_length = sprintf(buf, "\nOpens: %d Closes: %d Deletes: %d",
332 atomic_read(&tcon->num_opens),
333 atomic_read(&tcon->num_closes),
334 atomic_read(&tcon->num_deletes));
336 length += item_length;
337 item_length = sprintf(buf, "\nMkdirs: %d Rmdirs: %d",
338 atomic_read(&tcon->num_mkdirs),
339 atomic_read(&tcon->num_rmdirs));
341 length += item_length;
342 item_length = sprintf(buf, "\nRenames: %d T2 Renames %d",
343 atomic_read(&tcon->num_renames),
344 atomic_read(&tcon->num_t2renames));
346 length += item_length;
347 item_length = sprintf(buf, "\nFindFirst: %d FNext %d FClose %d",
348 atomic_read(&tcon->num_ffirst),
349 atomic_read(&tcon->num_fnext),
350 atomic_read(&tcon->num_fclose));
352 length += item_length;
354 read_unlock(&GlobalSMBSeslock);
356 buf += sprintf(buf,"\n");
359 if(offset + count >= length)
361 if(length < offset) {
365 length = length - offset;
374 static struct proc_dir_entry *proc_fs_cifs;
375 read_proc_t cifs_txanchor_read;
376 static read_proc_t cifsFYI_read;
377 static write_proc_t cifsFYI_write;
378 static read_proc_t oplockEnabled_read;
379 static write_proc_t oplockEnabled_write;
380 static read_proc_t lookupFlag_read;
381 static write_proc_t lookupFlag_write;
382 static read_proc_t traceSMB_read;
383 static write_proc_t traceSMB_write;
384 static read_proc_t multiuser_mount_read;
385 static write_proc_t multiuser_mount_write;
386 static read_proc_t extended_security_read;
387 static write_proc_t extended_security_write;
388 static read_proc_t ntlmv2_enabled_read;
389 static write_proc_t ntlmv2_enabled_write;
390 static read_proc_t packet_signing_enabled_read;
391 static write_proc_t packet_signing_enabled_write;
392 static read_proc_t quotaEnabled_read;
393 static write_proc_t quotaEnabled_write;
394 static read_proc_t linuxExtensionsEnabled_read;
395 static write_proc_t linuxExtensionsEnabled_write;
400 struct proc_dir_entry *pde;
402 proc_fs_cifs = proc_mkdir("cifs", proc_root_fs);
403 if (proc_fs_cifs == NULL)
406 proc_fs_cifs->owner = THIS_MODULE;
407 create_proc_read_entry("DebugData", 0, proc_fs_cifs,
408 cifs_debug_data_read, NULL);
410 #ifdef CONFIG_CIFS_STATS
411 pde = create_proc_read_entry("Stats", 0, proc_fs_cifs,
412 cifs_stats_read, NULL);
414 pde->write_proc = cifs_stats_write;
416 pde = create_proc_read_entry("cifsFYI", 0, proc_fs_cifs,
419 pde->write_proc = cifsFYI_write;
422 create_proc_read_entry("traceSMB", 0, proc_fs_cifs,
423 traceSMB_read, NULL);
425 pde->write_proc = traceSMB_write;
427 pde = create_proc_read_entry("OplockEnabled", 0, proc_fs_cifs,
428 oplockEnabled_read, NULL);
430 pde->write_proc = oplockEnabled_write;
432 pde = create_proc_read_entry("Experimental", 0, proc_fs_cifs,
433 quotaEnabled_read, NULL);
435 pde->write_proc = quotaEnabled_write;
437 pde = create_proc_read_entry("LinuxExtensionsEnabled", 0, proc_fs_cifs,
438 linuxExtensionsEnabled_read, NULL);
440 pde->write_proc = linuxExtensionsEnabled_write;
443 create_proc_read_entry("MultiuserMount", 0, proc_fs_cifs,
444 multiuser_mount_read, NULL);
446 pde->write_proc = multiuser_mount_write;
449 create_proc_read_entry("ExtendedSecurity", 0, proc_fs_cifs,
450 extended_security_read, NULL);
452 pde->write_proc = extended_security_write;
455 create_proc_read_entry("LookupCacheEnabled", 0, proc_fs_cifs,
456 lookupFlag_read, NULL);
458 pde->write_proc = lookupFlag_write;
461 create_proc_read_entry("NTLMV2Enabled", 0, proc_fs_cifs,
462 ntlmv2_enabled_read, NULL);
464 pde->write_proc = ntlmv2_enabled_write;
467 create_proc_read_entry("PacketSigningEnabled", 0, proc_fs_cifs,
468 packet_signing_enabled_read, NULL);
470 pde->write_proc = packet_signing_enabled_write;
474 cifs_proc_clean(void)
476 if (proc_fs_cifs == NULL)
479 remove_proc_entry("DebugData", proc_fs_cifs);
480 remove_proc_entry("cifsFYI", proc_fs_cifs);
481 remove_proc_entry("traceSMB", proc_fs_cifs);
482 #ifdef CONFIG_CIFS_STATS
483 remove_proc_entry("Stats", proc_fs_cifs);
485 remove_proc_entry("MultiuserMount", proc_fs_cifs);
486 remove_proc_entry("OplockEnabled", proc_fs_cifs);
487 remove_proc_entry("NTLMV2Enabled",proc_fs_cifs);
488 remove_proc_entry("ExtendedSecurity",proc_fs_cifs);
489 remove_proc_entry("PacketSigningEnabled",proc_fs_cifs);
490 remove_proc_entry("LinuxExtensionsEnabled",proc_fs_cifs);
491 remove_proc_entry("Experimental",proc_fs_cifs);
492 remove_proc_entry("LookupCacheEnabled",proc_fs_cifs);
493 remove_proc_entry("cifs", proc_root_fs);
497 cifsFYI_read(char *page, char **start, off_t off, int count,
498 int *eof, void *data)
502 len = sprintf(page, "%d\n", cifsFYI);
518 cifsFYI_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')
531 else if((c > '1') && (c <= '9'))
532 cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
538 oplockEnabled_read(char *page, char **start, off_t off,
539 int count, int *eof, void *data)
543 len = sprintf(page, "%d\n", oplockEnabled);
559 oplockEnabled_write(struct file *file, const char __user *buffer,
560 unsigned long count, void *data)
565 rc = get_user(c, buffer);
568 if (c == '0' || c == 'n' || c == 'N')
570 else if (c == '1' || c == 'y' || c == 'Y')
577 quotaEnabled_read(char *page, char **start, off_t off,
578 int count, int *eof, void *data)
582 len = sprintf(page, "%d\n", experimEnabled);
583 /* could also check if quotas are enabled in kernel
599 quotaEnabled_write(struct file *file, const char __user *buffer,
600 unsigned long count, void *data)
605 rc = get_user(c, buffer);
608 if (c == '0' || c == 'n' || c == 'N')
610 else if (c == '1' || c == 'y' || c == 'Y')
617 linuxExtensionsEnabled_read(char *page, char **start, off_t off,
618 int count, int *eof, void *data)
622 len = sprintf(page, "%d\n", linuxExtEnabled);
623 /* could also check if quotas are enabled in kernel
639 linuxExtensionsEnabled_write(struct file *file, const char __user *buffer,
640 unsigned long count, void *data)
645 rc = get_user(c, buffer);
648 if (c == '0' || c == 'n' || c == 'N')
650 else if (c == '1' || c == 'y' || c == 'Y')
658 lookupFlag_read(char *page, char **start, off_t off,
659 int count, int *eof, void *data)
663 len = sprintf(page, "%d\n", lookupCacheEnabled);
679 lookupFlag_write(struct file *file, const char __user *buffer,
680 unsigned long count, void *data)
685 rc = get_user(c, buffer);
688 if (c == '0' || c == 'n' || c == 'N')
689 lookupCacheEnabled = 0;
690 else if (c == '1' || c == 'y' || c == 'Y')
691 lookupCacheEnabled = 1;
696 traceSMB_read(char *page, char **start, off_t off, int count,
697 int *eof, void *data)
701 len = sprintf(page, "%d\n", traceSMB);
717 traceSMB_write(struct file *file, const char __user *buffer,
718 unsigned long count, void *data)
723 rc = get_user(c, buffer);
726 if (c == '0' || c == 'n' || c == 'N')
728 else if (c == '1' || c == 'y' || c == 'Y')
735 multiuser_mount_read(char *page, char **start, off_t off,
736 int count, int *eof, void *data)
740 len = sprintf(page, "%d\n", multiuser_mount);
756 multiuser_mount_write(struct file *file, const char __user *buffer,
757 unsigned long count, void *data)
762 rc = get_user(c, buffer);
765 if (c == '0' || c == 'n' || c == 'N')
767 else if (c == '1' || c == 'y' || c == 'Y')
774 extended_security_read(char *page, char **start, off_t off,
775 int count, int *eof, void *data)
779 len = sprintf(page, "%d\n", extended_security);
795 extended_security_write(struct file *file, const char __user *buffer,
796 unsigned long count, void *data)
801 rc = get_user(c, buffer);
804 if (c == '0' || c == 'n' || c == 'N')
805 extended_security = 0;
806 else if (c == '1' || c == 'y' || c == 'Y')
807 extended_security = 1;
813 ntlmv2_enabled_read(char *page, char **start, off_t off,
814 int count, int *eof, void *data)
818 len = sprintf(page, "%d\n", ntlmv2_support);
834 ntlmv2_enabled_write(struct file *file, const char __user *buffer,
835 unsigned long count, void *data)
840 rc = get_user(c, buffer);
843 if (c == '0' || c == 'n' || c == 'N')
845 else if (c == '1' || c == 'y' || c == 'Y')
852 packet_signing_enabled_read(char *page, char **start, off_t off,
853 int count, int *eof, void *data)
857 len = sprintf(page, "%d\n", sign_CIFS_PDUs);
873 packet_signing_enabled_write(struct file *file, const char __user *buffer,
874 unsigned long count, void *data)
879 rc = get_user(c, buffer);
882 if (c == '0' || c == 'n' || c == 'N')
884 else if (c == '1' || c == 'y' || c == 'Y')