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"
34 cifs_dump_mem(char *label, void *data, int length)
39 char buf[10], line[80];
41 printk(KERN_DEBUG "%s: dump of %d bytes of data at 0x%p\n\n",
43 for (i = 0; i < length; i += 16) {
45 for (j = 0; (j < 4) && (i + j * 4 < length); j++) {
46 sprintf(buf, " %08x", intptr[i / 4 + j]);
51 for (j = 0; (j < 16) && (i + j < length); j++) {
52 buf[1] = isprint(charptr[i + j]) ? charptr[i + j] : '.';
55 printk(KERN_DEBUG "%s\n", line);
61 cifs_debug_data_read(char *buf, char **beginBuffer, off_t offset,
62 int count, int *eof, void *data)
64 struct list_head *tmp;
65 struct list_head *tmp1;
66 struct mid_q_entry * mid_entry;
67 struct cifsSesInfo *ses;
68 struct cifsTconInfo *tcon;
71 char * original_buf = buf;
73 *beginBuffer = buf + offset;
78 "Display Internal CIFS Data Structures for Debugging\n"
79 "---------------------------------------------------\n");
82 length = sprintf(buf, "Servers:\n");
86 read_lock(&GlobalSMBSeslock);
87 list_for_each(tmp, &GlobalSMBSessionList) {
89 ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
92 "\n%d) Name: %s Domain: %s Mounts: %d ServerOS: %s \n\tServerNOS: %s\tCapabilities: 0x%x\n\tSMB session status: %d\tTCP status: %d",
93 i, ses->serverName, ses->serverDomain, atomic_read(&ses->inUse),
94 ses->serverOS, ses->serverNOS, ses->capabilities,ses->status,ses->server->tcpStatus);
97 buf += sprintf(buf, "\n\tLocal Users To Server: %d SecMode: 0x%x Req Active: %d",
98 atomic_read(&ses->server->socketUseCount),
100 atomic_read(&ses->server->inFlight));
102 length = sprintf(buf, "\nMIDs: \n");
105 spin_lock(&GlobalMid_Lock);
106 list_for_each(tmp1, &ses->server->pending_mid_q) {
107 mid_entry = list_entry(tmp1, struct
111 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);
115 spin_unlock(&GlobalMid_Lock);
119 read_unlock(&GlobalSMBSeslock);
123 length = sprintf(buf, "\nShares:\n");
127 read_lock(&GlobalSMBSeslock);
128 list_for_each(tmp, &GlobalTreeConnectionList) {
130 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
133 "\n%d) %s Uses: %d Type: %s Characteristics: 0x%x Attributes: 0x%x\nPathComponentMax: %d Status: %d",
135 atomic_read(&tcon->useCount),
136 tcon->nativeFileSystem,
137 tcon->fsDevInfo.DeviceCharacteristics,
138 tcon->fsAttrInfo.Attributes,
139 tcon->fsAttrInfo.MaxPathNameComponentLength,tcon->tidStatus);
141 if (tcon->fsDevInfo.DeviceType == FILE_DEVICE_DISK)
142 length = sprintf(buf, " type: DISK ");
143 else if (tcon->fsDevInfo.DeviceType == FILE_DEVICE_CD_ROM)
144 length = sprintf(buf, " type: CDROM ");
147 sprintf(buf, " type: %d ",
148 tcon->fsDevInfo.DeviceType);
150 if(tcon->tidStatus == CifsNeedReconnect) {
151 buf += sprintf(buf, "\tDISCONNECTED ");
155 read_unlock(&GlobalSMBSeslock);
157 length = sprintf(buf, "\n");
160 /* BB add code to dump additional info such as TCP session info now */
161 /* Now calculate total size of returned data */
162 length = buf - original_buf;
164 if(offset + count >= length)
166 if(length < offset) {
170 length = length - offset;
178 #ifdef CONFIG_CIFS_STATS
180 cifs_stats_read(char *buf, char **beginBuffer, off_t offset,
181 int count, int *eof, void *data)
183 int item_length,i,length;
184 struct list_head *tmp;
185 struct cifsTconInfo *tcon;
187 *beginBuffer = buf + offset;
189 length = sprintf(buf,
190 "Resources in use\nCIFS Session: %d\n",
191 sesInfoAllocCount.counter);
194 sprintf(buf,"Share (unique mount targets): %d\n",
195 tconInfoAllocCount.counter);
196 length += item_length;
199 sprintf(buf,"SMB Request/Response Buffer: %d\n",
200 bufAllocCount.counter);
201 length += item_length;
204 sprintf(buf,"Operations (MIDs): %d\n",
206 length += item_length;
208 item_length = sprintf(buf,
209 "\n%d session %d share reconnects\n",
210 tcpSesReconnectCount.counter,tconInfoReconnectCount.counter);
211 length += item_length;
214 item_length = sprintf(buf,
215 "Total vfs operations: %d maximum at one time: %d\n",
216 GlobalCurrentXid,GlobalMaxActiveXid);
217 length += item_length;
221 read_lock(&GlobalSMBSeslock);
222 list_for_each(tmp, &GlobalTreeConnectionList) {
224 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
225 item_length = sprintf(buf,"\n%d) %s",i, tcon->treeName);
227 length += item_length;
228 if(tcon->tidStatus == CifsNeedReconnect) {
229 buf += sprintf(buf, "\tDISCONNECTED ");
232 item_length = sprintf(buf,"\nSMBs: %d Oplock Breaks: %d",
233 atomic_read(&tcon->num_smbs_sent),
234 atomic_read(&tcon->num_oplock_brks));
236 length += item_length;
237 item_length = sprintf(buf,"\nReads: %d Bytes %lld",
238 atomic_read(&tcon->num_reads),
239 (long long)(tcon->bytes_read));
241 length += item_length;
242 item_length = sprintf(buf,"\nWrites: %d Bytes: %lld",
243 atomic_read(&tcon->num_writes),
244 (long long)(tcon->bytes_written));
246 length += item_length;
247 item_length = sprintf(buf,
248 "\nOpens: %d Deletes: %d\nMkdirs: %d Rmdirs: %d",
249 atomic_read(&tcon->num_opens),
250 atomic_read(&tcon->num_deletes),
251 atomic_read(&tcon->num_mkdirs),
252 atomic_read(&tcon->num_rmdirs));
254 length += item_length;
255 item_length = sprintf(buf,
256 "\nRenames: %d T2 Renames %d",
257 atomic_read(&tcon->num_renames),
258 atomic_read(&tcon->num_t2renames));
260 length += item_length;
262 read_unlock(&GlobalSMBSeslock);
264 buf += sprintf(buf,"\n");
267 if(offset + count >= length)
269 if(length < offset) {
273 length = length - offset;
282 struct proc_dir_entry *proc_fs_cifs;
283 read_proc_t cifs_txanchor_read;
284 static read_proc_t cifsFYI_read;
285 static write_proc_t cifsFYI_write;
286 static read_proc_t oplockEnabled_read;
287 static write_proc_t oplockEnabled_write;
288 static read_proc_t lookupFlag_read;
289 static write_proc_t lookupFlag_write;
290 static read_proc_t traceSMB_read;
291 static write_proc_t traceSMB_write;
292 static read_proc_t multiuser_mount_read;
293 static write_proc_t multiuser_mount_write;
294 static read_proc_t extended_security_read;
295 static write_proc_t extended_security_write;
296 static read_proc_t ntlmv2_enabled_read;
297 static write_proc_t ntlmv2_enabled_write;
298 static read_proc_t packet_signing_enabled_read;
299 static write_proc_t packet_signing_enabled_write;
300 static read_proc_t quotaEnabled_read;
301 static write_proc_t quotaEnabled_write;
302 static read_proc_t linuxExtensionsEnabled_read;
303 static write_proc_t linuxExtensionsEnabled_write;
308 struct proc_dir_entry *pde;
310 proc_fs_cifs = proc_mkdir("cifs", proc_root_fs);
311 if (proc_fs_cifs == NULL)
314 proc_fs_cifs->owner = THIS_MODULE;
315 create_proc_read_entry("DebugData", 0, proc_fs_cifs,
316 cifs_debug_data_read, NULL);
318 #ifdef CONFIG_CIFS_STATS
319 create_proc_read_entry("Stats", 0, proc_fs_cifs,
320 cifs_stats_read, NULL);
322 pde = create_proc_read_entry("cifsFYI", 0, proc_fs_cifs,
325 pde->write_proc = cifsFYI_write;
328 create_proc_read_entry("traceSMB", 0, proc_fs_cifs,
329 traceSMB_read, NULL);
331 pde->write_proc = traceSMB_write;
333 pde = create_proc_read_entry("OplockEnabled", 0, proc_fs_cifs,
334 oplockEnabled_read, NULL);
336 pde->write_proc = oplockEnabled_write;
338 pde = create_proc_read_entry("QuotaEnabled", 0, proc_fs_cifs,
339 quotaEnabled_read, NULL);
341 pde->write_proc = quotaEnabled_write;
343 pde = create_proc_read_entry("LinuxExtensionsEnabled", 0, proc_fs_cifs,
344 linuxExtensionsEnabled_read, NULL);
346 pde->write_proc = linuxExtensionsEnabled_write;
349 create_proc_read_entry("MultiuserMount", 0, proc_fs_cifs,
350 multiuser_mount_read, NULL);
352 pde->write_proc = multiuser_mount_write;
355 create_proc_read_entry("ExtendedSecurity", 0, proc_fs_cifs,
356 extended_security_read, NULL);
358 pde->write_proc = extended_security_write;
361 create_proc_read_entry("LookupCacheEnabled", 0, proc_fs_cifs,
362 lookupFlag_read, NULL);
364 pde->write_proc = lookupFlag_write;
367 create_proc_read_entry("NTLMV2Enabled", 0, proc_fs_cifs,
368 ntlmv2_enabled_read, NULL);
370 pde->write_proc = ntlmv2_enabled_write;
373 create_proc_read_entry("PacketSigningEnabled", 0, proc_fs_cifs,
374 packet_signing_enabled_read, NULL);
376 pde->write_proc = packet_signing_enabled_write;
380 cifs_proc_clean(void)
382 if (proc_fs_cifs == NULL)
385 remove_proc_entry("DebugData", proc_fs_cifs);
386 remove_proc_entry("cifsFYI", proc_fs_cifs);
387 remove_proc_entry("traceSMB", proc_fs_cifs);
388 #ifdef CONFIG_CIFS_STATS
389 remove_proc_entry("Stats", proc_fs_cifs);
391 remove_proc_entry("MultiuserMount", proc_fs_cifs);
392 remove_proc_entry("OplockEnabled", proc_fs_cifs);
393 remove_proc_entry("NTLMV2Enabled",proc_fs_cifs);
394 remove_proc_entry("ExtendedSecurity",proc_fs_cifs);
395 remove_proc_entry("PacketSigningEnabled",proc_fs_cifs);
396 remove_proc_entry("LinuxExtensionsEnabled",proc_fs_cifs);
397 remove_proc_entry("QuotaEnabled",proc_fs_cifs);
398 remove_proc_entry("LookupCacheEnabled",proc_fs_cifs);
399 remove_proc_entry("cifs", proc_root_fs);
403 cifsFYI_read(char *page, char **start, off_t off, int count,
404 int *eof, void *data)
408 len = sprintf(page, "%d\n", cifsFYI);
424 cifsFYI_write(struct file *file, const char __user *buffer,
425 unsigned long count, void *data)
430 rc = get_user(c, buffer);
433 if (c == '0' || c == 'n' || c == 'N')
435 else if (c == '1' || c == 'y' || c == 'Y')
442 oplockEnabled_read(char *page, char **start, off_t off,
443 int count, int *eof, void *data)
447 len = sprintf(page, "%d\n", oplockEnabled);
463 oplockEnabled_write(struct file *file, const char __user *buffer,
464 unsigned long count, void *data)
469 rc = get_user(c, buffer);
472 if (c == '0' || c == 'n' || c == 'N')
474 else if (c == '1' || c == 'y' || c == 'Y')
481 quotaEnabled_read(char *page, char **start, off_t off,
482 int count, int *eof, void *data)
486 len = sprintf(page, "%d\n", quotaEnabled);
487 /* could also check if quotas are enabled in kernel
503 quotaEnabled_write(struct file *file, const char __user *buffer,
504 unsigned long count, void *data)
509 rc = get_user(c, buffer);
512 if (c == '0' || c == 'n' || c == 'N')
514 else if (c == '1' || c == 'y' || c == 'Y')
521 linuxExtensionsEnabled_read(char *page, char **start, off_t off,
522 int count, int *eof, void *data)
526 len = sprintf(page, "%d\n", linuxExtEnabled);
527 /* could also check if quotas are enabled in kernel
543 linuxExtensionsEnabled_write(struct file *file, const char __user *buffer,
544 unsigned long count, void *data)
549 rc = get_user(c, buffer);
552 if (c == '0' || c == 'n' || c == 'N')
554 else if (c == '1' || c == 'y' || c == 'Y')
562 lookupFlag_read(char *page, char **start, off_t off,
563 int count, int *eof, void *data)
567 len = sprintf(page, "%d\n", lookupCacheEnabled);
583 lookupFlag_write(struct file *file, const char __user *buffer,
584 unsigned long count, void *data)
589 rc = get_user(c, buffer);
592 if (c == '0' || c == 'n' || c == 'N')
593 lookupCacheEnabled = 0;
594 else if (c == '1' || c == 'y' || c == 'Y')
595 lookupCacheEnabled = 1;
600 traceSMB_read(char *page, char **start, off_t off, int count,
601 int *eof, void *data)
605 len = sprintf(page, "%d\n", traceSMB);
621 traceSMB_write(struct file *file, const char __user *buffer,
622 unsigned long count, void *data)
627 rc = get_user(c, buffer);
630 if (c == '0' || c == 'n' || c == 'N')
632 else if (c == '1' || c == 'y' || c == 'Y')
639 multiuser_mount_read(char *page, char **start, off_t off,
640 int count, int *eof, void *data)
644 len = sprintf(page, "%d\n", multiuser_mount);
660 multiuser_mount_write(struct file *file, const char __user *buffer,
661 unsigned long count, void *data)
666 rc = get_user(c, buffer);
669 if (c == '0' || c == 'n' || c == 'N')
671 else if (c == '1' || c == 'y' || c == 'Y')
678 extended_security_read(char *page, char **start, off_t off,
679 int count, int *eof, void *data)
683 len = sprintf(page, "%d\n", extended_security);
699 extended_security_write(struct file *file, const char __user *buffer,
700 unsigned long count, void *data)
705 rc = get_user(c, buffer);
708 if (c == '0' || c == 'n' || c == 'N')
709 extended_security = 0;
710 else if (c == '1' || c == 'y' || c == 'Y')
711 extended_security = 1;
717 ntlmv2_enabled_read(char *page, char **start, off_t off,
718 int count, int *eof, void *data)
722 len = sprintf(page, "%d\n", ntlmv2_support);
738 ntlmv2_enabled_write(struct file *file, const char __user *buffer,
739 unsigned long count, void *data)
744 rc = get_user(c, buffer);
747 if (c == '0' || c == 'n' || c == 'N')
749 else if (c == '1' || c == 'y' || c == 'Y')
756 packet_signing_enabled_read(char *page, char **start, off_t off,
757 int count, int *eof, void *data)
761 len = sprintf(page, "%d\n", sign_CIFS_PDUs);
777 packet_signing_enabled_write(struct file *file, const char __user *buffer,
778 unsigned long count, void *data)
783 rc = get_user(c, buffer);
786 if (c == '0' || c == 'n' || c == 'N')
788 else if (c == '1' || c == 'y' || c == 'Y')