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",
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);
60 #ifdef CONFIG_CIFS_DEBUG2
61 void cifs_dump_detail(struct smb_hdr * smb)
63 cERROR(1,("Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d",
64 smb->Command, smb->Status.CifsError,
65 smb->Flags, smb->Flags2, smb->Mid, smb->Pid));
66 cERROR(1,("smb buf %p len %d", smb, smbCalcSize_LE(smb)));
70 void cifs_dump_mids(struct TCP_Server_Info * server)
72 struct list_head *tmp;
73 struct mid_q_entry * mid_entry;
78 cERROR(1,("Dump pending requests:"));
79 spin_lock(&GlobalMid_Lock);
80 list_for_each(tmp, &server->pending_mid_q) {
81 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
83 cERROR(1,("State: %d Cmd: %d Pid: %d Tsk: %p Mid %d",
85 (int)mid_entry->command,
89 #ifdef CONFIG_CIFS_STATS2
90 cERROR(1,("IsLarge: %d buf: %p time rcv: %ld now: %ld",
93 mid_entry->when_received,
96 cERROR(1,("IsMult: %d IsEnd: %d", mid_entry->multiRsp,
97 mid_entry->multiEnd));
98 if(mid_entry->resp_buf) {
99 cifs_dump_detail(mid_entry->resp_buf);
100 cifs_dump_mem("existing buf: ",
107 spin_unlock(&GlobalMid_Lock);
109 #endif /* CONFIG_CIFS_DEBUG2 */
111 #ifdef CONFIG_PROC_FS
113 cifs_debug_data_read(char *buf, char **beginBuffer, off_t offset,
114 int count, int *eof, void *data)
116 struct list_head *tmp;
117 struct list_head *tmp1;
118 struct mid_q_entry * mid_entry;
119 struct cifsSesInfo *ses;
120 struct cifsTconInfo *tcon;
123 char * original_buf = buf;
125 *beginBuffer = buf + offset;
129 "Display Internal CIFS Data Structures for Debugging\n"
130 "---------------------------------------------------\n");
132 length = sprintf(buf,"CIFS Version %s\n",CIFS_VERSION);
134 length = sprintf(buf,"Active VFS Requests: %d\n", GlobalTotalActiveXid);
136 length = sprintf(buf, "Servers:");
140 read_lock(&GlobalSMBSeslock);
141 list_for_each(tmp, &GlobalSMBSessionList) {
143 ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
144 if((ses->serverDomain == NULL) || (ses->serverOS == NULL) ||
145 (ses->serverNOS == NULL)) {
146 buf += sprintf(buf, "\nentry for %s not fully "
147 "displayed\n\t", ses->serverName);
152 "\n%d) Name: %s Domain: %s Mounts: %d OS: %s \n\tNOS: %s\tCapability: 0x%x\n\tSMB session status: %d\t",
153 i, ses->serverName, ses->serverDomain,
154 atomic_read(&ses->inUse),
155 ses->serverOS, ses->serverNOS,
156 ses->capabilities,ses->status);
160 buf += sprintf(buf, "TCP status: %d\n\tLocal Users To Server: %d SecMode: 0x%x Req On Wire: %d",
161 ses->server->tcpStatus,
162 atomic_read(&ses->server->socketUseCount),
163 ses->server->secMode,
164 atomic_read(&ses->server->inFlight));
166 #ifdef CONFIG_CIFS_STATS2
167 buf += sprintf(buf, " In Send: %d In MaxReq Wait: %d",
168 atomic_read(&ses->server->inSend),
169 atomic_read(&ses->server->num_waiters));
172 length = sprintf(buf, "\nMIDs:\n");
175 spin_lock(&GlobalMid_Lock);
176 list_for_each(tmp1, &ses->server->pending_mid_q) {
177 mid_entry = list_entry(tmp1, struct
181 length = sprintf(buf,"State: %d com: %d pid: %d tsk: %p mid %d\n",
183 (int)mid_entry->command,
190 spin_unlock(&GlobalMid_Lock);
194 read_unlock(&GlobalSMBSeslock);
198 length = sprintf(buf, "Shares:");
202 read_lock(&GlobalSMBSeslock);
203 list_for_each(tmp, &GlobalTreeConnectionList) {
206 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
207 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
210 "\n%d) %s Uses: %d Type: %s DevInfo: 0x%x Attributes: 0x%x\nPathComponentMax: %d Status: %d",
212 atomic_read(&tcon->useCount),
213 tcon->nativeFileSystem,
214 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
215 le32_to_cpu(tcon->fsAttrInfo.Attributes),
216 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
219 if (dev_type == FILE_DEVICE_DISK)
220 length = sprintf(buf, " type: DISK ");
221 else if (dev_type == FILE_DEVICE_CD_ROM)
222 length = sprintf(buf, " type: CDROM ");
225 sprintf(buf, " type: %d ", dev_type);
227 if(tcon->tidStatus == CifsNeedReconnect) {
228 buf += sprintf(buf, "\tDISCONNECTED ");
232 read_unlock(&GlobalSMBSeslock);
234 length = sprintf(buf, "\n");
237 /* BB add code to dump additional info such as TCP session info now */
238 /* Now calculate total size of returned data */
239 length = buf - original_buf;
241 if(offset + count >= length)
243 if(length < offset) {
247 length = length - offset;
255 #ifdef CONFIG_CIFS_STATS
258 cifs_stats_write(struct file *file, const char __user *buffer,
259 unsigned long count, void *data)
263 struct list_head *tmp;
264 struct cifsTconInfo *tcon;
266 rc = get_user(c, buffer);
270 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
271 read_lock(&GlobalSMBSeslock);
272 #ifdef CONFIG_CIFS_STATS2
273 atomic_set(&totBufAllocCount, 0);
274 atomic_set(&totSmBufAllocCount, 0);
275 #endif /* CONFIG_CIFS_STATS2 */
276 list_for_each(tmp, &GlobalTreeConnectionList) {
277 tcon = list_entry(tmp, struct cifsTconInfo,
279 atomic_set(&tcon->num_smbs_sent, 0);
280 atomic_set(&tcon->num_writes, 0);
281 atomic_set(&tcon->num_reads, 0);
282 atomic_set(&tcon->num_oplock_brks, 0);
283 atomic_set(&tcon->num_opens, 0);
284 atomic_set(&tcon->num_closes, 0);
285 atomic_set(&tcon->num_deletes, 0);
286 atomic_set(&tcon->num_mkdirs, 0);
287 atomic_set(&tcon->num_rmdirs, 0);
288 atomic_set(&tcon->num_renames, 0);
289 atomic_set(&tcon->num_t2renames, 0);
290 atomic_set(&tcon->num_ffirst, 0);
291 atomic_set(&tcon->num_fnext, 0);
292 atomic_set(&tcon->num_fclose, 0);
293 atomic_set(&tcon->num_hardlinks, 0);
294 atomic_set(&tcon->num_symlinks, 0);
295 atomic_set(&tcon->num_locks, 0);
297 read_unlock(&GlobalSMBSeslock);
304 cifs_stats_read(char *buf, char **beginBuffer, off_t offset,
305 int count, int *eof, void *data)
307 int item_length,i,length;
308 struct list_head *tmp;
309 struct cifsTconInfo *tcon;
311 *beginBuffer = buf + offset;
313 length = sprintf(buf,
314 "Resources in use\nCIFS Session: %d\n",
315 sesInfoAllocCount.counter);
318 sprintf(buf,"Share (unique mount targets): %d\n",
319 tconInfoAllocCount.counter);
320 length += item_length;
323 sprintf(buf,"SMB Request/Response Buffer: %d Pool size: %d\n",
324 bufAllocCount.counter,
325 cifs_min_rcv + tcpSesAllocCount.counter);
326 length += item_length;
329 sprintf(buf,"SMB Small Req/Resp Buffer: %d Pool size: %d\n",
330 smBufAllocCount.counter,cifs_min_small);
331 length += item_length;
333 #ifdef CONFIG_CIFS_STATS2
334 item_length = sprintf(buf, "Total Large %d Small %d Allocations\n",
335 atomic_read(&totBufAllocCount),
336 atomic_read(&totSmBufAllocCount));
337 length += item_length;
339 #endif /* CONFIG_CIFS_STATS2 */
342 sprintf(buf,"Operations (MIDs): %d\n",
344 length += item_length;
346 item_length = sprintf(buf,
347 "\n%d session %d share reconnects\n",
348 tcpSesReconnectCount.counter,tconInfoReconnectCount.counter);
349 length += item_length;
352 item_length = sprintf(buf,
353 "Total vfs operations: %d maximum at one time: %d\n",
354 GlobalCurrentXid,GlobalMaxActiveXid);
355 length += item_length;
359 read_lock(&GlobalSMBSeslock);
360 list_for_each(tmp, &GlobalTreeConnectionList) {
362 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
363 item_length = sprintf(buf,"\n%d) %s",i, tcon->treeName);
365 length += item_length;
366 if(tcon->tidStatus == CifsNeedReconnect) {
367 buf += sprintf(buf, "\tDISCONNECTED ");
370 item_length = sprintf(buf, "\nSMBs: %d Oplock Breaks: %d",
371 atomic_read(&tcon->num_smbs_sent),
372 atomic_read(&tcon->num_oplock_brks));
374 length += item_length;
375 item_length = sprintf(buf, "\nReads: %d Bytes: %lld",
376 atomic_read(&tcon->num_reads),
377 (long long)(tcon->bytes_read));
379 length += item_length;
380 item_length = sprintf(buf, "\nWrites: %d Bytes: %lld",
381 atomic_read(&tcon->num_writes),
382 (long long)(tcon->bytes_written));
384 length += item_length;
385 item_length = sprintf(buf,
386 "\nLocks: %d HardLinks: %d Symlinks: %d",
387 atomic_read(&tcon->num_locks),
388 atomic_read(&tcon->num_hardlinks),
389 atomic_read(&tcon->num_symlinks));
391 length += item_length;
393 item_length = sprintf(buf, "\nOpens: %d Closes: %d Deletes: %d",
394 atomic_read(&tcon->num_opens),
395 atomic_read(&tcon->num_closes),
396 atomic_read(&tcon->num_deletes));
398 length += item_length;
399 item_length = sprintf(buf, "\nMkdirs: %d Rmdirs: %d",
400 atomic_read(&tcon->num_mkdirs),
401 atomic_read(&tcon->num_rmdirs));
403 length += item_length;
404 item_length = sprintf(buf, "\nRenames: %d T2 Renames %d",
405 atomic_read(&tcon->num_renames),
406 atomic_read(&tcon->num_t2renames));
408 length += item_length;
409 item_length = sprintf(buf, "\nFindFirst: %d FNext %d FClose %d",
410 atomic_read(&tcon->num_ffirst),
411 atomic_read(&tcon->num_fnext),
412 atomic_read(&tcon->num_fclose));
414 length += item_length;
416 read_unlock(&GlobalSMBSeslock);
418 buf += sprintf(buf,"\n");
421 if(offset + count >= length)
423 if(length < offset) {
427 length = length - offset;
436 static struct proc_dir_entry *proc_fs_cifs;
437 read_proc_t cifs_txanchor_read;
438 static read_proc_t cifsFYI_read;
439 static write_proc_t cifsFYI_write;
440 static read_proc_t oplockEnabled_read;
441 static write_proc_t oplockEnabled_write;
442 static read_proc_t lookupFlag_read;
443 static write_proc_t lookupFlag_write;
444 static read_proc_t traceSMB_read;
445 static write_proc_t traceSMB_write;
446 static read_proc_t multiuser_mount_read;
447 static write_proc_t multiuser_mount_write;
448 static read_proc_t security_flags_read;
449 static write_proc_t security_flags_write;
450 /* static read_proc_t ntlmv2_enabled_read;
451 static write_proc_t ntlmv2_enabled_write;
452 static read_proc_t packet_signing_enabled_read;
453 static write_proc_t packet_signing_enabled_write;*/
454 static read_proc_t experimEnabled_read;
455 static write_proc_t experimEnabled_write;
456 static read_proc_t linuxExtensionsEnabled_read;
457 static write_proc_t linuxExtensionsEnabled_write;
462 struct proc_dir_entry *pde;
464 proc_fs_cifs = proc_mkdir("cifs", proc_root_fs);
465 if (proc_fs_cifs == NULL)
468 proc_fs_cifs->owner = THIS_MODULE;
469 create_proc_read_entry("DebugData", 0, proc_fs_cifs,
470 cifs_debug_data_read, NULL);
472 #ifdef CONFIG_CIFS_STATS
473 pde = create_proc_read_entry("Stats", 0, proc_fs_cifs,
474 cifs_stats_read, NULL);
476 pde->write_proc = cifs_stats_write;
478 pde = create_proc_read_entry("cifsFYI", 0, proc_fs_cifs,
481 pde->write_proc = cifsFYI_write;
484 create_proc_read_entry("traceSMB", 0, proc_fs_cifs,
485 traceSMB_read, NULL);
487 pde->write_proc = traceSMB_write;
489 pde = create_proc_read_entry("OplockEnabled", 0, proc_fs_cifs,
490 oplockEnabled_read, NULL);
492 pde->write_proc = oplockEnabled_write;
494 pde = create_proc_read_entry("Experimental", 0, proc_fs_cifs,
495 experimEnabled_read, NULL);
497 pde->write_proc = experimEnabled_write;
499 pde = create_proc_read_entry("LinuxExtensionsEnabled", 0, proc_fs_cifs,
500 linuxExtensionsEnabled_read, NULL);
502 pde->write_proc = linuxExtensionsEnabled_write;
505 create_proc_read_entry("MultiuserMount", 0, proc_fs_cifs,
506 multiuser_mount_read, NULL);
508 pde->write_proc = multiuser_mount_write;
511 create_proc_read_entry("SecurityFlags", 0, proc_fs_cifs,
512 security_flags_read, NULL);
514 pde->write_proc = security_flags_write;
517 create_proc_read_entry("LookupCacheEnabled", 0, proc_fs_cifs,
518 lookupFlag_read, NULL);
520 pde->write_proc = lookupFlag_write;
523 create_proc_read_entry("NTLMV2Enabled", 0, proc_fs_cifs,
524 ntlmv2_enabled_read, NULL);
526 pde->write_proc = ntlmv2_enabled_write;
529 create_proc_read_entry("PacketSigningEnabled", 0, proc_fs_cifs,
530 packet_signing_enabled_read, NULL);
532 pde->write_proc = packet_signing_enabled_write;*/
536 cifs_proc_clean(void)
538 if (proc_fs_cifs == NULL)
541 remove_proc_entry("DebugData", proc_fs_cifs);
542 remove_proc_entry("cifsFYI", proc_fs_cifs);
543 remove_proc_entry("traceSMB", proc_fs_cifs);
544 #ifdef CONFIG_CIFS_STATS
545 remove_proc_entry("Stats", proc_fs_cifs);
547 remove_proc_entry("MultiuserMount", proc_fs_cifs);
548 remove_proc_entry("OplockEnabled", proc_fs_cifs);
549 /* remove_proc_entry("NTLMV2Enabled",proc_fs_cifs); */
550 remove_proc_entry("SecurityFlags",proc_fs_cifs);
551 /* remove_proc_entry("PacketSigningEnabled",proc_fs_cifs); */
552 remove_proc_entry("LinuxExtensionsEnabled",proc_fs_cifs);
553 remove_proc_entry("Experimental",proc_fs_cifs);
554 remove_proc_entry("LookupCacheEnabled",proc_fs_cifs);
555 remove_proc_entry("cifs", proc_root_fs);
559 cifsFYI_read(char *page, char **start, off_t off, int count,
560 int *eof, void *data)
564 len = sprintf(page, "%d\n", cifsFYI);
580 cifsFYI_write(struct file *file, const char __user *buffer,
581 unsigned long count, void *data)
586 rc = get_user(c, buffer);
589 if (c == '0' || c == 'n' || c == 'N')
591 else if (c == '1' || c == 'y' || c == 'Y')
593 else if((c > '1') && (c <= '9'))
594 cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
600 oplockEnabled_read(char *page, char **start, off_t off,
601 int count, int *eof, void *data)
605 len = sprintf(page, "%d\n", oplockEnabled);
621 oplockEnabled_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 experimEnabled_read(char *page, char **start, off_t off,
640 int count, int *eof, void *data)
644 len = sprintf(page, "%d\n", experimEnabled);
660 experimEnabled_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')
680 linuxExtensionsEnabled_read(char *page, char **start, off_t off,
681 int count, int *eof, void *data)
685 len = sprintf(page, "%d\n", linuxExtEnabled);
700 linuxExtensionsEnabled_write(struct file *file, const char __user *buffer,
701 unsigned long count, void *data)
706 rc = get_user(c, buffer);
709 if (c == '0' || c == 'n' || c == 'N')
711 else if (c == '1' || c == 'y' || c == 'Y')
719 lookupFlag_read(char *page, char **start, off_t off,
720 int count, int *eof, void *data)
724 len = sprintf(page, "%d\n", lookupCacheEnabled);
740 lookupFlag_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 lookupCacheEnabled = 0;
751 else if (c == '1' || c == 'y' || c == 'Y')
752 lookupCacheEnabled = 1;
757 traceSMB_read(char *page, char **start, off_t off, int count,
758 int *eof, void *data)
762 len = sprintf(page, "%d\n", traceSMB);
778 traceSMB_write(struct file *file, const char __user *buffer,
779 unsigned long count, void *data)
784 rc = get_user(c, buffer);
787 if (c == '0' || c == 'n' || c == 'N')
789 else if (c == '1' || c == 'y' || c == 'Y')
796 multiuser_mount_read(char *page, char **start, off_t off,
797 int count, int *eof, void *data)
801 len = sprintf(page, "%d\n", multiuser_mount);
817 multiuser_mount_write(struct file *file, const char __user *buffer,
818 unsigned long count, void *data)
823 rc = get_user(c, buffer);
826 if (c == '0' || c == 'n' || c == 'N')
828 else if (c == '1' || c == 'y' || c == 'Y')
835 security_flags_read(char *page, char **start, off_t off,
836 int count, int *eof, void *data)
840 len = sprintf(page, "0x%x\n", extended_security);
856 security_flags_write(struct file *file, const char __user *buffer,
857 unsigned long count, void *data)
860 char flags_string[12];
863 if((count < 1) || (count > 11))
866 memset(flags_string, 0, 12);
868 if(copy_from_user(flags_string, buffer, count))
872 /* single char or single char followed by null */
874 if (c == '0' || c == 'n' || c == 'N')
875 extended_security = CIFSSEC_DEF; /* default */
876 else if (c == '1' || c == 'y' || c == 'Y')
877 extended_security = CIFSSEC_MAX;
880 /* else we have a number */
882 flags = simple_strtoul(flags_string, NULL, 0);
884 cFYI(1,("sec flags 0x%x", flags));
887 cERROR(1,("invalid security flags %s",flags_string));
891 if(flags & ~CIFSSEC_MASK) {
892 cERROR(1,("attempt to set unsupported security flags 0x%x",
893 flags & ~CIFSSEC_MASK));
896 /* flags look ok - update the global security flags for cifs module */
897 extended_security = flags;
902 ntlmv2_enabled_read(char *page, char **start, off_t off,
903 int count, int *eof, void *data)
907 len = sprintf(page, "%d\n", ntlmv2_support);
923 ntlmv2_enabled_write(struct file *file, const char __user *buffer,
924 unsigned long count, void *data)
929 rc = get_user(c, buffer);
932 if (c == '0' || c == 'n' || c == 'N')
934 else if (c == '1' || c == 'y' || c == 'Y')
943 packet_signing_enabled_read(char *page, char **start, off_t off,
944 int count, int *eof, void *data)
948 len = sprintf(page, "%d\n", sign_CIFS_PDUs);
964 packet_signing_enabled_write(struct file *file, const char __user *buffer,
965 unsigned long count, void *data)
970 rc = get_user(c, buffer);
973 if (c == '0' || c == 'n' || c == 'N')
975 else if (c == '1' || c == 'y' || c == 'Y')