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);
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,
96 atomic_read(&ses->inUse),
97 ses->serverOS, ses->serverNOS,
98 ses->capabilities,ses->status);
101 buf += sprintf(buf, "TCP status: %d\n\tLocal Users To Server: %d SecMode: 0x%x Req Active: %d",
102 ses->server->tcpStatus,
103 atomic_read(&ses->server->socketUseCount),
104 ses->server->secMode,
105 atomic_read(&ses->server->inFlight));
107 length = sprintf(buf, "\nMIDs:\n");
110 spin_lock(&GlobalMid_Lock);
111 list_for_each(tmp1, &ses->server->pending_mid_q) {
112 mid_entry = list_entry(tmp1, struct
116 length = sprintf(buf,"State: %d com: %d pid: %d tsk: %p mid %d\n",
118 (int)mid_entry->command,
125 spin_unlock(&GlobalMid_Lock);
129 read_unlock(&GlobalSMBSeslock);
133 length = sprintf(buf, "Shares:");
137 read_lock(&GlobalSMBSeslock);
138 list_for_each(tmp, &GlobalTreeConnectionList) {
141 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
142 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
145 "\n%d) %s Uses: %d Type: %s Characteristics: 0x%x Attributes: 0x%x\nPathComponentMax: %d Status: %d",
147 atomic_read(&tcon->useCount),
148 tcon->nativeFileSystem,
149 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
150 le32_to_cpu(tcon->fsAttrInfo.Attributes),
151 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
154 if (dev_type == FILE_DEVICE_DISK)
155 length = sprintf(buf, " type: DISK ");
156 else if (dev_type == FILE_DEVICE_CD_ROM)
157 length = sprintf(buf, " type: CDROM ");
160 sprintf(buf, " type: %d ", dev_type);
162 if(tcon->tidStatus == CifsNeedReconnect) {
163 buf += sprintf(buf, "\tDISCONNECTED ");
167 read_unlock(&GlobalSMBSeslock);
169 length = sprintf(buf, "\n");
172 /* BB add code to dump additional info such as TCP session info now */
173 /* Now calculate total size of returned data */
174 length = buf - original_buf;
176 if(offset + count >= length)
178 if(length < offset) {
182 length = length - offset;
190 #ifdef CONFIG_CIFS_STATS
192 cifs_stats_read(char *buf, char **beginBuffer, off_t offset,
193 int count, int *eof, void *data)
195 int item_length,i,length;
196 struct list_head *tmp;
197 struct cifsTconInfo *tcon;
199 *beginBuffer = buf + offset;
201 length = sprintf(buf,
202 "Resources in use\nCIFS Session: %d\n",
203 sesInfoAllocCount.counter);
206 sprintf(buf,"Share (unique mount targets): %d\n",
207 tconInfoAllocCount.counter);
208 length += item_length;
211 sprintf(buf,"SMB Request/Response Buffer: %d Pool size: %d\n",
212 bufAllocCount.counter,
213 cifs_min_rcv + tcpSesAllocCount.counter);
214 length += item_length;
217 sprintf(buf,"SMB Small Req/Resp Buffer: %d Pool size: %d\n",
218 smBufAllocCount.counter,cifs_min_small);
219 length += item_length;
222 sprintf(buf,"Operations (MIDs): %d\n",
224 length += item_length;
226 item_length = sprintf(buf,
227 "\n%d session %d share reconnects\n",
228 tcpSesReconnectCount.counter,tconInfoReconnectCount.counter);
229 length += item_length;
232 item_length = sprintf(buf,
233 "Total vfs operations: %d maximum at one time: %d\n",
234 GlobalCurrentXid,GlobalMaxActiveXid);
235 length += item_length;
239 read_lock(&GlobalSMBSeslock);
240 list_for_each(tmp, &GlobalTreeConnectionList) {
242 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
243 item_length = sprintf(buf,"\n%d) %s",i, tcon->treeName);
245 length += item_length;
246 if(tcon->tidStatus == CifsNeedReconnect) {
247 buf += sprintf(buf, "\tDISCONNECTED ");
250 item_length = sprintf(buf,"\nSMBs: %d Oplock Breaks: %d",
251 atomic_read(&tcon->num_smbs_sent),
252 atomic_read(&tcon->num_oplock_brks));
254 length += item_length;
255 item_length = sprintf(buf,"\nReads: %d Bytes %lld",
256 atomic_read(&tcon->num_reads),
257 (long long)(tcon->bytes_read));
259 length += item_length;
260 item_length = sprintf(buf,"\nWrites: %d Bytes: %lld",
261 atomic_read(&tcon->num_writes),
262 (long long)(tcon->bytes_written));
264 length += item_length;
265 item_length = sprintf(buf,
266 "\nOpens: %d Deletes: %d\nMkdirs: %d Rmdirs: %d",
267 atomic_read(&tcon->num_opens),
268 atomic_read(&tcon->num_deletes),
269 atomic_read(&tcon->num_mkdirs),
270 atomic_read(&tcon->num_rmdirs));
272 length += item_length;
273 item_length = sprintf(buf,
274 "\nRenames: %d T2 Renames %d",
275 atomic_read(&tcon->num_renames),
276 atomic_read(&tcon->num_t2renames));
278 length += item_length;
280 read_unlock(&GlobalSMBSeslock);
282 buf += sprintf(buf,"\n");
285 if(offset + count >= length)
287 if(length < offset) {
291 length = length - offset;
300 static struct proc_dir_entry *proc_fs_cifs;
301 read_proc_t cifs_txanchor_read;
302 static read_proc_t cifsFYI_read;
303 static write_proc_t cifsFYI_write;
304 static read_proc_t oplockEnabled_read;
305 static write_proc_t oplockEnabled_write;
306 static read_proc_t lookupFlag_read;
307 static write_proc_t lookupFlag_write;
308 static read_proc_t traceSMB_read;
309 static write_proc_t traceSMB_write;
310 static read_proc_t multiuser_mount_read;
311 static write_proc_t multiuser_mount_write;
312 static read_proc_t extended_security_read;
313 static write_proc_t extended_security_write;
314 static read_proc_t ntlmv2_enabled_read;
315 static write_proc_t ntlmv2_enabled_write;
316 static read_proc_t packet_signing_enabled_read;
317 static write_proc_t packet_signing_enabled_write;
318 static read_proc_t quotaEnabled_read;
319 static write_proc_t quotaEnabled_write;
320 static read_proc_t linuxExtensionsEnabled_read;
321 static write_proc_t linuxExtensionsEnabled_write;
326 struct proc_dir_entry *pde;
328 proc_fs_cifs = proc_mkdir("cifs", proc_root_fs);
329 if (proc_fs_cifs == NULL)
332 proc_fs_cifs->owner = THIS_MODULE;
333 create_proc_read_entry("DebugData", 0, proc_fs_cifs,
334 cifs_debug_data_read, NULL);
336 #ifdef CONFIG_CIFS_STATS
337 create_proc_read_entry("Stats", 0, proc_fs_cifs,
338 cifs_stats_read, NULL);
340 pde = create_proc_read_entry("cifsFYI", 0, proc_fs_cifs,
343 pde->write_proc = cifsFYI_write;
346 create_proc_read_entry("traceSMB", 0, proc_fs_cifs,
347 traceSMB_read, NULL);
349 pde->write_proc = traceSMB_write;
351 pde = create_proc_read_entry("OplockEnabled", 0, proc_fs_cifs,
352 oplockEnabled_read, NULL);
354 pde->write_proc = oplockEnabled_write;
356 pde = create_proc_read_entry("ReenableOldCifsReaddirCode", 0, proc_fs_cifs,
357 quotaEnabled_read, NULL);
359 pde->write_proc = quotaEnabled_write;
361 pde = create_proc_read_entry("LinuxExtensionsEnabled", 0, proc_fs_cifs,
362 linuxExtensionsEnabled_read, NULL);
364 pde->write_proc = linuxExtensionsEnabled_write;
367 create_proc_read_entry("MultiuserMount", 0, proc_fs_cifs,
368 multiuser_mount_read, NULL);
370 pde->write_proc = multiuser_mount_write;
373 create_proc_read_entry("ExtendedSecurity", 0, proc_fs_cifs,
374 extended_security_read, NULL);
376 pde->write_proc = extended_security_write;
379 create_proc_read_entry("LookupCacheEnabled", 0, proc_fs_cifs,
380 lookupFlag_read, NULL);
382 pde->write_proc = lookupFlag_write;
385 create_proc_read_entry("NTLMV2Enabled", 0, proc_fs_cifs,
386 ntlmv2_enabled_read, NULL);
388 pde->write_proc = ntlmv2_enabled_write;
391 create_proc_read_entry("PacketSigningEnabled", 0, proc_fs_cifs,
392 packet_signing_enabled_read, NULL);
394 pde->write_proc = packet_signing_enabled_write;
398 cifs_proc_clean(void)
400 if (proc_fs_cifs == NULL)
403 remove_proc_entry("DebugData", proc_fs_cifs);
404 remove_proc_entry("cifsFYI", proc_fs_cifs);
405 remove_proc_entry("traceSMB", proc_fs_cifs);
406 #ifdef CONFIG_CIFS_STATS
407 remove_proc_entry("Stats", proc_fs_cifs);
409 remove_proc_entry("MultiuserMount", proc_fs_cifs);
410 remove_proc_entry("OplockEnabled", proc_fs_cifs);
411 remove_proc_entry("NTLMV2Enabled",proc_fs_cifs);
412 remove_proc_entry("ExtendedSecurity",proc_fs_cifs);
413 remove_proc_entry("PacketSigningEnabled",proc_fs_cifs);
414 remove_proc_entry("LinuxExtensionsEnabled",proc_fs_cifs);
415 remove_proc_entry("ReenableOldCifsReaddirCode",proc_fs_cifs);
416 remove_proc_entry("LookupCacheEnabled",proc_fs_cifs);
417 remove_proc_entry("cifs", proc_root_fs);
421 cifsFYI_read(char *page, char **start, off_t off, int count,
422 int *eof, void *data)
426 len = sprintf(page, "%d\n", cifsFYI);
442 cifsFYI_write(struct file *file, const char __user *buffer,
443 unsigned long count, void *data)
448 rc = get_user(c, buffer);
451 if (c == '0' || c == 'n' || c == 'N')
453 else if (c == '1' || c == 'y' || c == 'Y')
460 oplockEnabled_read(char *page, char **start, off_t off,
461 int count, int *eof, void *data)
465 len = sprintf(page, "%d\n", oplockEnabled);
481 oplockEnabled_write(struct file *file, const char __user *buffer,
482 unsigned long count, void *data)
487 rc = get_user(c, buffer);
490 if (c == '0' || c == 'n' || c == 'N')
492 else if (c == '1' || c == 'y' || c == 'Y')
499 quotaEnabled_read(char *page, char **start, off_t off,
500 int count, int *eof, void *data)
504 len = sprintf(page, "%d\n", experimEnabled);
505 /* could also check if quotas are enabled in kernel
521 quotaEnabled_write(struct file *file, const char __user *buffer,
522 unsigned long count, void *data)
527 rc = get_user(c, buffer);
530 if (c == '0' || c == 'n' || c == 'N')
532 else if (c == '1' || c == 'y' || c == 'Y')
539 linuxExtensionsEnabled_read(char *page, char **start, off_t off,
540 int count, int *eof, void *data)
544 len = sprintf(page, "%d\n", linuxExtEnabled);
545 /* could also check if quotas are enabled in kernel
561 linuxExtensionsEnabled_write(struct file *file, const char __user *buffer,
562 unsigned long count, void *data)
567 rc = get_user(c, buffer);
570 if (c == '0' || c == 'n' || c == 'N')
572 else if (c == '1' || c == 'y' || c == 'Y')
580 lookupFlag_read(char *page, char **start, off_t off,
581 int count, int *eof, void *data)
585 len = sprintf(page, "%d\n", lookupCacheEnabled);
601 lookupFlag_write(struct file *file, const char __user *buffer,
602 unsigned long count, void *data)
607 rc = get_user(c, buffer);
610 if (c == '0' || c == 'n' || c == 'N')
611 lookupCacheEnabled = 0;
612 else if (c == '1' || c == 'y' || c == 'Y')
613 lookupCacheEnabled = 1;
618 traceSMB_read(char *page, char **start, off_t off, int count,
619 int *eof, void *data)
623 len = sprintf(page, "%d\n", traceSMB);
639 traceSMB_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')
657 multiuser_mount_read(char *page, char **start, off_t off,
658 int count, int *eof, void *data)
662 len = sprintf(page, "%d\n", multiuser_mount);
678 multiuser_mount_write(struct file *file, const char __user *buffer,
679 unsigned long count, void *data)
684 rc = get_user(c, buffer);
687 if (c == '0' || c == 'n' || c == 'N')
689 else if (c == '1' || c == 'y' || c == 'Y')
696 extended_security_read(char *page, char **start, off_t off,
697 int count, int *eof, void *data)
701 len = sprintf(page, "%d\n", extended_security);
717 extended_security_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')
727 extended_security = 0;
728 else if (c == '1' || c == 'y' || c == 'Y')
729 extended_security = 1;
735 ntlmv2_enabled_read(char *page, char **start, off_t off,
736 int count, int *eof, void *data)
740 len = sprintf(page, "%d\n", ntlmv2_support);
756 ntlmv2_enabled_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 packet_signing_enabled_read(char *page, char **start, off_t off,
775 int count, int *eof, void *data)
779 len = sprintf(page, "%d\n", sign_CIFS_PDUs);
795 packet_signing_enabled_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')
806 else if (c == '1' || c == 'y' || c == 'Y')