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: ",
106 spin_unlock(&GlobalMid_Lock);
108 #endif /* CONFIG_CIFS_DEBUG2 */
110 #ifdef CONFIG_PROC_FS
112 cifs_debug_data_read(char *buf, char **beginBuffer, off_t offset,
113 int count, int *eof, void *data)
115 struct list_head *tmp;
116 struct list_head *tmp1;
117 struct mid_q_entry * mid_entry;
118 struct cifsSesInfo *ses;
119 struct cifsTconInfo *tcon;
122 char * original_buf = buf;
124 *beginBuffer = buf + offset;
128 "Display Internal CIFS Data Structures for Debugging\n"
129 "---------------------------------------------------\n");
131 length = sprintf(buf, "CIFS Version %s\n", CIFS_VERSION);
133 length = sprintf(buf,
134 "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:"
153 " %s \n\tNOS: %s\tCapability: 0x%x\n\tSMB"
154 " session status: %d\t",
155 i, ses->serverName, ses->serverDomain,
156 atomic_read(&ses->inUse),
157 ses->serverOS, ses->serverNOS,
158 ses->capabilities, ses->status);
162 buf += sprintf(buf, "TCP status: %d\n\tLocal Users To "
163 "Server: %d SecMode: 0x%x Req On Wire: %d",
164 ses->server->tcpStatus,
165 atomic_read(&ses->server->socketUseCount),
166 ses->server->secMode,
167 atomic_read(&ses->server->inFlight));
169 #ifdef CONFIG_CIFS_STATS2
170 buf += sprintf(buf, " In Send: %d In MaxReq Wait: %d",
171 atomic_read(&ses->server->inSend),
172 atomic_read(&ses->server->num_waiters));
175 length = sprintf(buf, "\nMIDs:\n");
178 spin_lock(&GlobalMid_Lock);
179 list_for_each(tmp1, &ses->server->pending_mid_q) {
180 mid_entry = list_entry(tmp1, struct
184 length = sprintf(buf,
185 "State: %d com: %d pid:"
186 " %d tsk: %p mid %d\n",
188 (int)mid_entry->command,
195 spin_unlock(&GlobalMid_Lock);
199 read_unlock(&GlobalSMBSeslock);
203 length = sprintf(buf, "Shares:");
207 read_lock(&GlobalSMBSeslock);
208 list_for_each(tmp, &GlobalTreeConnectionList) {
211 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
212 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
215 "\n%d) %s Uses: %d Type: %s DevInfo: 0x%x "
216 "Attributes: 0x%x\nPathComponentMax: %d Status: %d",
218 atomic_read(&tcon->useCount),
219 tcon->nativeFileSystem,
220 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
221 le32_to_cpu(tcon->fsAttrInfo.Attributes),
222 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
225 if (dev_type == FILE_DEVICE_DISK)
226 length = sprintf(buf, " type: DISK ");
227 else if (dev_type == FILE_DEVICE_CD_ROM)
228 length = sprintf(buf, " type: CDROM ");
231 sprintf(buf, " type: %d ", dev_type);
233 if (tcon->tidStatus == CifsNeedReconnect) {
234 buf += sprintf(buf, "\tDISCONNECTED ");
238 read_unlock(&GlobalSMBSeslock);
240 length = sprintf(buf, "\n");
243 /* BB add code to dump additional info such as TCP session info now */
244 /* Now calculate total size of returned data */
245 length = buf - original_buf;
247 if (offset + count >= length)
249 if (length < offset) {
253 length = length - offset;
261 #ifdef CONFIG_CIFS_STATS
264 cifs_stats_write(struct file *file, const char __user *buffer,
265 unsigned long count, void *data)
269 struct list_head *tmp;
270 struct cifsTconInfo *tcon;
272 rc = get_user(c, buffer);
276 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
277 read_lock(&GlobalSMBSeslock);
278 #ifdef CONFIG_CIFS_STATS2
279 atomic_set(&totBufAllocCount, 0);
280 atomic_set(&totSmBufAllocCount, 0);
281 #endif /* CONFIG_CIFS_STATS2 */
282 list_for_each(tmp, &GlobalTreeConnectionList) {
283 tcon = list_entry(tmp, struct cifsTconInfo,
285 atomic_set(&tcon->num_smbs_sent, 0);
286 atomic_set(&tcon->num_writes, 0);
287 atomic_set(&tcon->num_reads, 0);
288 atomic_set(&tcon->num_oplock_brks, 0);
289 atomic_set(&tcon->num_opens, 0);
290 atomic_set(&tcon->num_closes, 0);
291 atomic_set(&tcon->num_deletes, 0);
292 atomic_set(&tcon->num_mkdirs, 0);
293 atomic_set(&tcon->num_rmdirs, 0);
294 atomic_set(&tcon->num_renames, 0);
295 atomic_set(&tcon->num_t2renames, 0);
296 atomic_set(&tcon->num_ffirst, 0);
297 atomic_set(&tcon->num_fnext, 0);
298 atomic_set(&tcon->num_fclose, 0);
299 atomic_set(&tcon->num_hardlinks, 0);
300 atomic_set(&tcon->num_symlinks, 0);
301 atomic_set(&tcon->num_locks, 0);
303 read_unlock(&GlobalSMBSeslock);
310 cifs_stats_read(char *buf, char **beginBuffer, off_t offset,
311 int count, int *eof, void *data)
313 int item_length, i, length;
314 struct list_head *tmp;
315 struct cifsTconInfo *tcon;
317 *beginBuffer = buf + offset;
319 length = sprintf(buf,
320 "Resources in use\nCIFS Session: %d\n",
321 sesInfoAllocCount.counter);
324 sprintf(buf, "Share (unique mount targets): %d\n",
325 tconInfoAllocCount.counter);
326 length += item_length;
329 sprintf(buf, "SMB Request/Response Buffer: %d Pool size: %d\n",
330 bufAllocCount.counter,
331 cifs_min_rcv + tcpSesAllocCount.counter);
332 length += item_length;
335 sprintf(buf, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
336 smBufAllocCount.counter, cifs_min_small);
337 length += item_length;
339 #ifdef CONFIG_CIFS_STATS2
340 item_length = sprintf(buf, "Total Large %d Small %d Allocations\n",
341 atomic_read(&totBufAllocCount),
342 atomic_read(&totSmBufAllocCount));
343 length += item_length;
345 #endif /* CONFIG_CIFS_STATS2 */
348 sprintf(buf, "Operations (MIDs): %d\n",
350 length += item_length;
352 item_length = sprintf(buf,
353 "\n%d session %d share reconnects\n",
354 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
355 length += item_length;
358 item_length = sprintf(buf,
359 "Total vfs operations: %d maximum at one time: %d\n",
360 GlobalCurrentXid, GlobalMaxActiveXid);
361 length += item_length;
365 read_lock(&GlobalSMBSeslock);
366 list_for_each(tmp, &GlobalTreeConnectionList) {
368 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
369 item_length = sprintf(buf, "\n%d) %s", i, tcon->treeName);
371 length += item_length;
372 if (tcon->tidStatus == CifsNeedReconnect) {
373 buf += sprintf(buf, "\tDISCONNECTED ");
376 item_length = sprintf(buf, "\nSMBs: %d Oplock Breaks: %d",
377 atomic_read(&tcon->num_smbs_sent),
378 atomic_read(&tcon->num_oplock_brks));
380 length += item_length;
381 item_length = sprintf(buf, "\nReads: %d Bytes: %lld",
382 atomic_read(&tcon->num_reads),
383 (long long)(tcon->bytes_read));
385 length += item_length;
386 item_length = sprintf(buf, "\nWrites: %d Bytes: %lld",
387 atomic_read(&tcon->num_writes),
388 (long long)(tcon->bytes_written));
390 length += item_length;
391 item_length = sprintf(buf,
392 "\nLocks: %d HardLinks: %d Symlinks: %d",
393 atomic_read(&tcon->num_locks),
394 atomic_read(&tcon->num_hardlinks),
395 atomic_read(&tcon->num_symlinks));
397 length += item_length;
399 item_length = sprintf(buf, "\nOpens: %d Closes: %d Deletes: %d",
400 atomic_read(&tcon->num_opens),
401 atomic_read(&tcon->num_closes),
402 atomic_read(&tcon->num_deletes));
404 length += item_length;
405 item_length = sprintf(buf, "\nMkdirs: %d Rmdirs: %d",
406 atomic_read(&tcon->num_mkdirs),
407 atomic_read(&tcon->num_rmdirs));
409 length += item_length;
410 item_length = sprintf(buf, "\nRenames: %d T2 Renames %d",
411 atomic_read(&tcon->num_renames),
412 atomic_read(&tcon->num_t2renames));
414 length += item_length;
415 item_length = sprintf(buf, "\nFindFirst: %d FNext %d FClose %d",
416 atomic_read(&tcon->num_ffirst),
417 atomic_read(&tcon->num_fnext),
418 atomic_read(&tcon->num_fclose));
420 length += item_length;
422 read_unlock(&GlobalSMBSeslock);
424 buf += sprintf(buf, "\n");
427 if (offset + count >= length)
429 if (length < offset) {
433 length = length - offset;
442 static struct proc_dir_entry *proc_fs_cifs;
443 read_proc_t cifs_txanchor_read;
444 static read_proc_t cifsFYI_read;
445 static write_proc_t cifsFYI_write;
446 static read_proc_t oplockEnabled_read;
447 static write_proc_t oplockEnabled_write;
448 static read_proc_t lookupFlag_read;
449 static write_proc_t lookupFlag_write;
450 static read_proc_t traceSMB_read;
451 static write_proc_t traceSMB_write;
452 static read_proc_t multiuser_mount_read;
453 static write_proc_t multiuser_mount_write;
454 static read_proc_t security_flags_read;
455 static write_proc_t security_flags_write;
456 /* static read_proc_t ntlmv2_enabled_read;
457 static write_proc_t ntlmv2_enabled_write;
458 static read_proc_t packet_signing_enabled_read;
459 static write_proc_t packet_signing_enabled_write;*/
460 static read_proc_t experimEnabled_read;
461 static write_proc_t experimEnabled_write;
462 static read_proc_t linuxExtensionsEnabled_read;
463 static write_proc_t linuxExtensionsEnabled_write;
468 struct proc_dir_entry *pde;
470 proc_fs_cifs = proc_mkdir("cifs", proc_root_fs);
471 if (proc_fs_cifs == NULL)
474 proc_fs_cifs->owner = THIS_MODULE;
475 create_proc_read_entry("DebugData", 0, proc_fs_cifs,
476 cifs_debug_data_read, NULL);
478 #ifdef CONFIG_CIFS_STATS
479 pde = create_proc_read_entry("Stats", 0, proc_fs_cifs,
480 cifs_stats_read, NULL);
482 pde->write_proc = cifs_stats_write;
484 pde = create_proc_read_entry("cifsFYI", 0, proc_fs_cifs,
487 pde->write_proc = cifsFYI_write;
490 create_proc_read_entry("traceSMB", 0, proc_fs_cifs,
491 traceSMB_read, NULL);
493 pde->write_proc = traceSMB_write;
495 pde = create_proc_read_entry("OplockEnabled", 0, proc_fs_cifs,
496 oplockEnabled_read, NULL);
498 pde->write_proc = oplockEnabled_write;
500 pde = create_proc_read_entry("Experimental", 0, proc_fs_cifs,
501 experimEnabled_read, NULL);
503 pde->write_proc = experimEnabled_write;
505 pde = create_proc_read_entry("LinuxExtensionsEnabled", 0, proc_fs_cifs,
506 linuxExtensionsEnabled_read, NULL);
508 pde->write_proc = linuxExtensionsEnabled_write;
511 create_proc_read_entry("MultiuserMount", 0, proc_fs_cifs,
512 multiuser_mount_read, NULL);
514 pde->write_proc = multiuser_mount_write;
517 create_proc_read_entry("SecurityFlags", 0, proc_fs_cifs,
518 security_flags_read, NULL);
520 pde->write_proc = security_flags_write;
523 create_proc_read_entry("LookupCacheEnabled", 0, proc_fs_cifs,
524 lookupFlag_read, NULL);
526 pde->write_proc = lookupFlag_write;
529 create_proc_read_entry("NTLMV2Enabled", 0, proc_fs_cifs,
530 ntlmv2_enabled_read, NULL);
532 pde->write_proc = ntlmv2_enabled_write;
535 create_proc_read_entry("PacketSigningEnabled", 0, proc_fs_cifs,
536 packet_signing_enabled_read, NULL);
538 pde->write_proc = packet_signing_enabled_write;*/
542 cifs_proc_clean(void)
544 if (proc_fs_cifs == NULL)
547 remove_proc_entry("DebugData", proc_fs_cifs);
548 remove_proc_entry("cifsFYI", proc_fs_cifs);
549 remove_proc_entry("traceSMB", proc_fs_cifs);
550 #ifdef CONFIG_CIFS_STATS
551 remove_proc_entry("Stats", proc_fs_cifs);
553 remove_proc_entry("MultiuserMount", proc_fs_cifs);
554 remove_proc_entry("OplockEnabled", proc_fs_cifs);
555 /* remove_proc_entry("NTLMV2Enabled",proc_fs_cifs); */
556 remove_proc_entry("SecurityFlags", proc_fs_cifs);
557 /* remove_proc_entry("PacketSigningEnabled", proc_fs_cifs); */
558 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
559 remove_proc_entry("Experimental", proc_fs_cifs);
560 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
561 remove_proc_entry("cifs", proc_root_fs);
565 cifsFYI_read(char *page, char **start, off_t off, int count,
566 int *eof, void *data)
570 len = sprintf(page, "%d\n", cifsFYI);
586 cifsFYI_write(struct file *file, const char __user *buffer,
587 unsigned long count, void *data)
592 rc = get_user(c, buffer);
595 if (c == '0' || c == 'n' || c == 'N')
597 else if (c == '1' || c == 'y' || c == 'Y')
599 else if ((c > '1') && (c <= '9'))
600 cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
606 oplockEnabled_read(char *page, char **start, off_t off,
607 int count, int *eof, void *data)
611 len = sprintf(page, "%d\n", oplockEnabled);
627 oplockEnabled_write(struct file *file, const char __user *buffer,
628 unsigned long count, void *data)
633 rc = get_user(c, buffer);
636 if (c == '0' || c == 'n' || c == 'N')
638 else if (c == '1' || c == 'y' || c == 'Y')
645 experimEnabled_read(char *page, char **start, off_t off,
646 int count, int *eof, void *data)
650 len = sprintf(page, "%d\n", experimEnabled);
666 experimEnabled_write(struct file *file, const char __user *buffer,
667 unsigned long count, void *data)
672 rc = get_user(c, buffer);
675 if (c == '0' || c == 'n' || c == 'N')
677 else if (c == '1' || c == 'y' || c == 'Y')
686 linuxExtensionsEnabled_read(char *page, char **start, off_t off,
687 int count, int *eof, void *data)
691 len = sprintf(page, "%d\n", linuxExtEnabled);
706 linuxExtensionsEnabled_write(struct file *file, const char __user *buffer,
707 unsigned long count, void *data)
712 rc = get_user(c, buffer);
715 if (c == '0' || c == 'n' || c == 'N')
717 else if (c == '1' || c == 'y' || c == 'Y')
725 lookupFlag_read(char *page, char **start, off_t off,
726 int count, int *eof, void *data)
730 len = sprintf(page, "%d\n", lookupCacheEnabled);
746 lookupFlag_write(struct file *file, const char __user *buffer,
747 unsigned long count, void *data)
752 rc = get_user(c, buffer);
755 if (c == '0' || c == 'n' || c == 'N')
756 lookupCacheEnabled = 0;
757 else if (c == '1' || c == 'y' || c == 'Y')
758 lookupCacheEnabled = 1;
763 traceSMB_read(char *page, char **start, off_t off, int count,
764 int *eof, void *data)
768 len = sprintf(page, "%d\n", traceSMB);
784 traceSMB_write(struct file *file, const char __user *buffer,
785 unsigned long count, void *data)
790 rc = get_user(c, buffer);
793 if (c == '0' || c == 'n' || c == 'N')
795 else if (c == '1' || c == 'y' || c == 'Y')
802 multiuser_mount_read(char *page, char **start, off_t off,
803 int count, int *eof, void *data)
807 len = sprintf(page, "%d\n", multiuser_mount);
823 multiuser_mount_write(struct file *file, const char __user *buffer,
824 unsigned long count, void *data)
829 rc = get_user(c, buffer);
832 if (c == '0' || c == 'n' || c == 'N')
834 else if (c == '1' || c == 'y' || c == 'Y')
841 security_flags_read(char *page, char **start, off_t off,
842 int count, int *eof, void *data)
846 len = sprintf(page, "0x%x\n", extended_security);
862 security_flags_write(struct file *file, const char __user *buffer,
863 unsigned long count, void *data)
866 char flags_string[12];
869 if ((count < 1) || (count > 11))
872 memset(flags_string, 0, 12);
874 if (copy_from_user(flags_string, buffer, count))
878 /* single char or single char followed by null */
880 if (c == '0' || c == 'n' || c == 'N')
881 extended_security = CIFSSEC_DEF; /* default */
882 else if (c == '1' || c == 'y' || c == 'Y')
883 extended_security = CIFSSEC_MAX;
886 /* else we have a number */
888 flags = simple_strtoul(flags_string, NULL, 0);
890 cFYI(1, ("sec flags 0x%x", flags));
893 cERROR(1, ("invalid security flags %s", flags_string));
897 if (flags & ~CIFSSEC_MASK) {
898 cERROR(1, ("attempt to set unsupported security flags 0x%x",
899 flags & ~CIFSSEC_MASK));
902 /* flags look ok - update the global security flags for cifs module */
903 extended_security = flags;
908 ntlmv2_enabled_read(char *page, char **start, off_t off,
909 int count, int *eof, void *data)
913 len = sprintf(page, "%d\n", ntlmv2_support);
929 ntlmv2_enabled_write(struct file *file, const char __user *buffer,
930 unsigned long count, void *data)
935 rc = get_user(c, buffer);
938 if (c == '0' || c == 'n' || c == 'N')
940 else if (c == '1' || c == 'y' || c == 'Y')
949 packet_signing_enabled_read(char *page, char **start, off_t off,
950 int count, int *eof, void *data)
954 len = sprintf(page, "%d\n", sign_CIFS_PDUs);
970 packet_signing_enabled_write(struct file *file, const char __user *buffer,
971 unsigned long count, void *data)
976 rc = get_user(c, buffer);
979 if (c == '0' || c == 'n' || c == 'N')
981 else if (c == '1' || c == 'y' || c == 'Y')