blob: 96abeb7389784d4e3f5fa6eb4ee72ea8d66b947a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * fs/cifs_debug.c
3 *
Steve Frenchb8643e12005-04-28 22:41:07 -07004 * Copyright (C) International Business Machines Corp., 2000,2005
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 *
6 * Modified by Steve French (sfrench@us.ibm.com)
7 *
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.
12 *
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.
17 *
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
21 */
22#include <linux/fs.h>
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>
28#include "cifspdu.h"
29#include "cifsglob.h"
30#include "cifsproto.h"
31#include "cifs_debug.h"
Steve French6c91d362005-04-28 22:41:06 -070032#include "cifsfs.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34void
35cifs_dump_mem(char *label, void *data, int length)
36{
37 int i, j;
38 int *intptr = data;
39 char *charptr = data;
40 char buf[10], line[80];
41
Steve French39798772006-05-31 22:40:51 +000042 printk(KERN_DEBUG "%s: dump of %d bytes of data at 0x%p\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 label, length, data);
44 for (i = 0; i < length; i += 16) {
45 line[0] = 0;
46 for (j = 0; (j < 4) && (i + j * 4 < length); j++) {
47 sprintf(buf, " %08x", intptr[i / 4 + j]);
48 strcat(line, buf);
49 }
50 buf[0] = ' ';
51 buf[2] = 0;
52 for (j = 0; (j < 16) && (i + j < length); j++) {
53 buf[1] = isprint(charptr[i + j]) ? charptr[i + j] : '.';
54 strcat(line, buf);
55 }
56 printk(KERN_DEBUG "%s\n", line);
57 }
58}
59
Steve French39798772006-05-31 22:40:51 +000060#ifdef CONFIG_CIFS_DEBUG2
61void cifs_dump_detail(struct smb_hdr * smb)
62{
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)));
67}
68
69
70void cifs_dump_mids(struct TCP_Server_Info * server)
71{
72 struct list_head *tmp;
73 struct mid_q_entry * mid_entry;
74
75 if(server == NULL)
76 return;
77
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);
82 if(mid_entry) {
83 cERROR(1,("State: %d Cmd: %d Pid: %d Tsk: %p Mid %d",
84 mid_entry->midState,
85 (int)mid_entry->command,
86 mid_entry->pid,
87 mid_entry->tsk,
88 mid_entry->mid));
89#ifdef CONFIG_CIFS_STATS2
90 cERROR(1,("IsLarge: %d buf: %p time rcv: %ld now: %ld",
91 mid_entry->largeBuf,
92 mid_entry->resp_buf,
93 mid_entry->when_received,
94 jiffies));
95#endif /* STATS2 */
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: ",
101 mid_entry->resp_buf,
102 62 /* fixme */);
103 }
104
105 }
106 }
107 spin_unlock(&GlobalMid_Lock);
108}
109#endif /* CONFIG_CIFS_DEBUG2 */
110
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111#ifdef CONFIG_PROC_FS
112static int
113cifs_debug_data_read(char *buf, char **beginBuffer, off_t offset,
114 int count, int *eof, void *data)
115{
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;
121 int i;
122 int length = 0;
123 char * original_buf = buf;
124
125 *beginBuffer = buf + offset;
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 length =
128 sprintf(buf,
129 "Display Internal CIFS Data Structures for Debugging\n"
130 "---------------------------------------------------\n");
131 buf += length;
Steve French6c91d362005-04-28 22:41:06 -0700132 length = sprintf(buf,"CIFS Version %s\n",CIFS_VERSION);
133 buf += length;
Steve French131afd0b2005-10-07 09:51:05 -0700134 length = sprintf(buf,"Active VFS Requests: %d\n", GlobalTotalActiveXid);
135 buf += length;
Steve French6c91d362005-04-28 22:41:06 -0700136 length = sprintf(buf, "Servers:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 buf += length;
138
139 i = 0;
140 read_lock(&GlobalSMBSeslock);
141 list_for_each(tmp, &GlobalSMBSessionList) {
142 i++;
143 ses = list_entry(tmp, struct cifsSesInfo, cifsSessionList);
Steve French433dc242005-04-28 22:41:08 -0700144 if((ses->serverDomain == NULL) || (ses->serverOS == NULL) ||
145 (ses->serverNOS == NULL)) {
146 buf += sprintf("\nentry for %s not fully displayed\n\t",
147 ses->serverName);
148
149 } else {
150 length =
151 sprintf(buf,
Steve French131afd0b2005-10-07 09:51:05 -0700152 "\n%d) Name: %s Domain: %s Mounts: %d OS: %s \n\tNOS: %s\tCapability: 0x%x\n\tSMB session status: %d\t",
Steve Frenchb8643e12005-04-28 22:41:07 -0700153 i, ses->serverName, ses->serverDomain,
154 atomic_read(&ses->inUse),
155 ses->serverOS, ses->serverNOS,
156 ses->capabilities,ses->status);
Steve French433dc242005-04-28 22:41:08 -0700157 buf += length;
158 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 if(ses->server) {
Steve French131afd0b2005-10-07 09:51:05 -0700160 buf += sprintf(buf, "TCP status: %d\n\tLocal Users To Server: %d SecMode: 0x%x Req On Wire: %d",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 ses->server->tcpStatus,
162 atomic_read(&ses->server->socketUseCount),
163 ses->server->secMode,
164 atomic_read(&ses->server->inFlight));
Steve French131afd0b2005-10-07 09:51:05 -0700165
166#ifdef CONFIG_CIFS_STATS2
Steve French68058e72005-10-10 10:34:22 -0700167 buf += sprintf(buf, " In Send: %d In MaxReq Wait: %d",
Steve French131afd0b2005-10-07 09:51:05 -0700168 atomic_read(&ses->server->inSend),
169 atomic_read(&ses->server->num_waiters));
170#endif
171
Steve French6c91d362005-04-28 22:41:06 -0700172 length = sprintf(buf, "\nMIDs:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 buf += length;
174
175 spin_lock(&GlobalMid_Lock);
176 list_for_each(tmp1, &ses->server->pending_mid_q) {
177 mid_entry = list_entry(tmp1, struct
178 mid_q_entry,
179 qhead);
180 if(mid_entry) {
Steve French848f3fc2005-04-28 22:41:07 -0700181 length = sprintf(buf,"State: %d com: %d pid: %d tsk: %p mid %d\n",
182 mid_entry->midState,
183 (int)mid_entry->command,
184 mid_entry->pid,
185 mid_entry->tsk,
186 mid_entry->mid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 buf += length;
188 }
189 }
190 spin_unlock(&GlobalMid_Lock);
191 }
192
193 }
194 read_unlock(&GlobalSMBSeslock);
195 sprintf(buf, "\n");
196 buf++;
197
Steve French6c91d362005-04-28 22:41:06 -0700198 length = sprintf(buf, "Shares:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 buf += length;
200
201 i = 0;
202 read_lock(&GlobalSMBSeslock);
203 list_for_each(tmp, &GlobalTreeConnectionList) {
204 __u32 dev_type;
205 i++;
206 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
207 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
208 length =
209 sprintf(buf,
Steve French131afd0b2005-10-07 09:51:05 -0700210 "\n%d) %s Uses: %d Type: %s DevInfo: 0x%x Attributes: 0x%x\nPathComponentMax: %d Status: %d",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 i, tcon->treeName,
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),
217 tcon->tidStatus);
218 buf += length;
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 ");
223 else
224 length =
225 sprintf(buf, " type: %d ", dev_type);
226 buf += length;
227 if(tcon->tidStatus == CifsNeedReconnect) {
228 buf += sprintf(buf, "\tDISCONNECTED ");
229 length += 14;
230 }
231 }
232 read_unlock(&GlobalSMBSeslock);
233
234 length = sprintf(buf, "\n");
235 buf += length;
236
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;
240
241 if(offset + count >= length)
242 *eof = 1;
243 if(length < offset) {
244 *eof = 1;
245 return 0;
246 } else {
247 length = length - offset;
248 }
249 if (length > count)
250 length = count;
251
252 return length;
253}
254
255#ifdef CONFIG_CIFS_STATS
Steve French1047abc2005-10-11 19:58:06 -0700256
257static int
258cifs_stats_write(struct file *file, const char __user *buffer,
259 unsigned long count, void *data)
260{
261 char c;
262 int rc;
263 struct list_head *tmp;
264 struct cifsTconInfo *tcon;
265
266 rc = get_user(c, buffer);
267 if (rc)
268 return rc;
269
Steve French47c786e2005-10-11 20:03:18 -0700270 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
Steve French1047abc2005-10-11 19:58:06 -0700271 read_lock(&GlobalSMBSeslock);
Steve French4498eed52005-12-03 13:58:57 -0800272#ifdef CONFIG_CIFS_STATS2
273 atomic_set(&totBufAllocCount, 0);
274 atomic_set(&totSmBufAllocCount, 0);
275#endif /* CONFIG_CIFS_STATS2 */
Steve French1047abc2005-10-11 19:58:06 -0700276 list_for_each(tmp, &GlobalTreeConnectionList) {
277 tcon = list_entry(tmp, struct cifsTconInfo,
278 cifsConnectionList);
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);
296 }
297 read_unlock(&GlobalSMBSeslock);
298 }
299
300 return count;
301}
302
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303static int
304cifs_stats_read(char *buf, char **beginBuffer, off_t offset,
305 int count, int *eof, void *data)
306{
307 int item_length,i,length;
308 struct list_head *tmp;
309 struct cifsTconInfo *tcon;
310
311 *beginBuffer = buf + offset;
312
313 length = sprintf(buf,
314 "Resources in use\nCIFS Session: %d\n",
315 sesInfoAllocCount.counter);
316 buf += length;
317 item_length =
318 sprintf(buf,"Share (unique mount targets): %d\n",
319 tconInfoAllocCount.counter);
320 length += item_length;
321 buf += item_length;
322 item_length =
323 sprintf(buf,"SMB Request/Response Buffer: %d Pool size: %d\n",
Steve Frenchb8643e12005-04-28 22:41:07 -0700324 bufAllocCount.counter,
325 cifs_min_rcv + tcpSesAllocCount.counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 length += item_length;
327 buf += item_length;
328 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;
332 buf += item_length;
Steve French07475ff2005-12-03 14:11:37 -0800333#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;
338 buf += item_length;
339#endif /* CONFIG_CIFS_STATS2 */
340
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 item_length =
342 sprintf(buf,"Operations (MIDs): %d\n",
343 midCount.counter);
344 length += item_length;
345 buf += item_length;
346 item_length = sprintf(buf,
347 "\n%d session %d share reconnects\n",
348 tcpSesReconnectCount.counter,tconInfoReconnectCount.counter);
349 length += item_length;
350 buf += item_length;
351
352 item_length = sprintf(buf,
353 "Total vfs operations: %d maximum at one time: %d\n",
354 GlobalCurrentXid,GlobalMaxActiveXid);
355 length += item_length;
356 buf += item_length;
357
358 i = 0;
359 read_lock(&GlobalSMBSeslock);
360 list_for_each(tmp, &GlobalTreeConnectionList) {
361 i++;
362 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
363 item_length = sprintf(buf,"\n%d) %s",i, tcon->treeName);
364 buf += item_length;
365 length += item_length;
366 if(tcon->tidStatus == CifsNeedReconnect) {
367 buf += sprintf(buf, "\tDISCONNECTED ");
368 length += 14;
369 }
Steve Frencha5a2b482005-08-20 21:42:53 -0700370 item_length = sprintf(buf, "\nSMBs: %d Oplock Breaks: %d",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 atomic_read(&tcon->num_smbs_sent),
372 atomic_read(&tcon->num_oplock_brks));
373 buf += item_length;
374 length += item_length;
Steve French0ae0efa2005-10-10 10:57:19 -0700375 item_length = sprintf(buf, "\nReads: %d Bytes: %lld",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376 atomic_read(&tcon->num_reads),
377 (long long)(tcon->bytes_read));
378 buf += item_length;
379 length += item_length;
Steve Frencha5a2b482005-08-20 21:42:53 -0700380 item_length = sprintf(buf, "\nWrites: %d Bytes: %lld",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 atomic_read(&tcon->num_writes),
382 (long long)(tcon->bytes_written));
Steve Frencha5a2b482005-08-20 21:42:53 -0700383 buf += item_length;
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));
390 buf += item_length;
391 length += item_length;
392
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));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 buf += item_length;
398 length += item_length;
Steve Frencha5a2b482005-08-20 21:42:53 -0700399 item_length = sprintf(buf, "\nMkdirs: %d Rmdirs: %d",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 atomic_read(&tcon->num_mkdirs),
401 atomic_read(&tcon->num_rmdirs));
402 buf += item_length;
403 length += item_length;
Steve Frencha5a2b482005-08-20 21:42:53 -0700404 item_length = sprintf(buf, "\nRenames: %d T2 Renames %d",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 atomic_read(&tcon->num_renames),
406 atomic_read(&tcon->num_t2renames));
407 buf += item_length;
408 length += item_length;
Steve Frencha5a2b482005-08-20 21:42:53 -0700409 item_length = sprintf(buf, "\nFindFirst: %d FNext %d FClose %d",
Steve French0c0ff092005-06-23 19:31:17 -0500410 atomic_read(&tcon->num_ffirst),
411 atomic_read(&tcon->num_fnext),
412 atomic_read(&tcon->num_fclose));
413 buf += item_length;
414 length += item_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 }
416 read_unlock(&GlobalSMBSeslock);
417
418 buf += sprintf(buf,"\n");
419 length++;
420
421 if(offset + count >= length)
422 *eof = 1;
423 if(length < offset) {
424 *eof = 1;
425 return 0;
426 } else {
427 length = length - offset;
428 }
429 if (length > count)
430 length = count;
431
432 return length;
433}
434#endif
435
436static struct proc_dir_entry *proc_fs_cifs;
437read_proc_t cifs_txanchor_read;
438static read_proc_t cifsFYI_read;
439static write_proc_t cifsFYI_write;
440static read_proc_t oplockEnabled_read;
441static write_proc_t oplockEnabled_write;
442static read_proc_t lookupFlag_read;
443static write_proc_t lookupFlag_write;
444static read_proc_t traceSMB_read;
445static write_proc_t traceSMB_write;
446static read_proc_t multiuser_mount_read;
447static write_proc_t multiuser_mount_write;
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000448static read_proc_t security_flags_read;
449static write_proc_t security_flags_write;
Steve French39798772006-05-31 22:40:51 +0000450/* static read_proc_t ntlmv2_enabled_read;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451static write_proc_t ntlmv2_enabled_write;
452static read_proc_t packet_signing_enabled_read;
Steve French39798772006-05-31 22:40:51 +0000453static write_proc_t packet_signing_enabled_write;*/
Steve Frenchec637e32005-12-12 20:53:18 -0800454static read_proc_t experimEnabled_read;
455static write_proc_t experimEnabled_write;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456static read_proc_t linuxExtensionsEnabled_read;
457static write_proc_t linuxExtensionsEnabled_write;
458
459void
460cifs_proc_init(void)
461{
462 struct proc_dir_entry *pde;
463
464 proc_fs_cifs = proc_mkdir("cifs", proc_root_fs);
465 if (proc_fs_cifs == NULL)
466 return;
467
468 proc_fs_cifs->owner = THIS_MODULE;
469 create_proc_read_entry("DebugData", 0, proc_fs_cifs,
470 cifs_debug_data_read, NULL);
471
472#ifdef CONFIG_CIFS_STATS
Steve French1047abc2005-10-11 19:58:06 -0700473 pde = create_proc_read_entry("Stats", 0, proc_fs_cifs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 cifs_stats_read, NULL);
Steve French1047abc2005-10-11 19:58:06 -0700475 if (pde)
476 pde->write_proc = cifs_stats_write;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477#endif
478 pde = create_proc_read_entry("cifsFYI", 0, proc_fs_cifs,
479 cifsFYI_read, NULL);
480 if (pde)
481 pde->write_proc = cifsFYI_write;
482
483 pde =
484 create_proc_read_entry("traceSMB", 0, proc_fs_cifs,
485 traceSMB_read, NULL);
486 if (pde)
487 pde->write_proc = traceSMB_write;
488
489 pde = create_proc_read_entry("OplockEnabled", 0, proc_fs_cifs,
490 oplockEnabled_read, NULL);
491 if (pde)
492 pde->write_proc = oplockEnabled_write;
493
Steve French0c0ff092005-06-23 19:31:17 -0500494 pde = create_proc_read_entry("Experimental", 0, proc_fs_cifs,
Steve Frenchec637e32005-12-12 20:53:18 -0800495 experimEnabled_read, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 if (pde)
Steve Frenchec637e32005-12-12 20:53:18 -0800497 pde->write_proc = experimEnabled_write;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
499 pde = create_proc_read_entry("LinuxExtensionsEnabled", 0, proc_fs_cifs,
500 linuxExtensionsEnabled_read, NULL);
501 if (pde)
502 pde->write_proc = linuxExtensionsEnabled_write;
503
504 pde =
505 create_proc_read_entry("MultiuserMount", 0, proc_fs_cifs,
506 multiuser_mount_read, NULL);
507 if (pde)
508 pde->write_proc = multiuser_mount_write;
509
510 pde =
Steve French7c7b25b2006-06-01 19:20:10 +0000511 create_proc_read_entry("SecurityFlags", 0, proc_fs_cifs,
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000512 security_flags_read, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 if (pde)
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000514 pde->write_proc = security_flags_write;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
516 pde =
517 create_proc_read_entry("LookupCacheEnabled", 0, proc_fs_cifs,
518 lookupFlag_read, NULL);
519 if (pde)
520 pde->write_proc = lookupFlag_write;
521
Steve French39798772006-05-31 22:40:51 +0000522/* pde =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 create_proc_read_entry("NTLMV2Enabled", 0, proc_fs_cifs,
524 ntlmv2_enabled_read, NULL);
525 if (pde)
526 pde->write_proc = ntlmv2_enabled_write;
527
528 pde =
529 create_proc_read_entry("PacketSigningEnabled", 0, proc_fs_cifs,
530 packet_signing_enabled_read, NULL);
531 if (pde)
Steve French39798772006-05-31 22:40:51 +0000532 pde->write_proc = packet_signing_enabled_write;*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533}
534
535void
536cifs_proc_clean(void)
537{
538 if (proc_fs_cifs == NULL)
539 return;
540
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);
546#endif
547 remove_proc_entry("MultiuserMount", proc_fs_cifs);
548 remove_proc_entry("OplockEnabled", proc_fs_cifs);
Steve French39798772006-05-31 22:40:51 +0000549/* remove_proc_entry("NTLMV2Enabled",proc_fs_cifs); */
Steve French7c7b25b2006-06-01 19:20:10 +0000550 remove_proc_entry("SecurityFlags",proc_fs_cifs);
Steve French39798772006-05-31 22:40:51 +0000551/* remove_proc_entry("PacketSigningEnabled",proc_fs_cifs); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 remove_proc_entry("LinuxExtensionsEnabled",proc_fs_cifs);
Steve French0c0ff092005-06-23 19:31:17 -0500553 remove_proc_entry("Experimental",proc_fs_cifs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 remove_proc_entry("LookupCacheEnabled",proc_fs_cifs);
555 remove_proc_entry("cifs", proc_root_fs);
556}
557
558static int
559cifsFYI_read(char *page, char **start, off_t off, int count,
560 int *eof, void *data)
561{
562 int len;
563
564 len = sprintf(page, "%d\n", cifsFYI);
565
566 len -= off;
567 *start = page + off;
568
569 if (len > count)
570 len = count;
571 else
572 *eof = 1;
573
574 if (len < 0)
575 len = 0;
576
577 return len;
578}
579static int
580cifsFYI_write(struct file *file, const char __user *buffer,
581 unsigned long count, void *data)
582{
583 char c;
584 int rc;
585
586 rc = get_user(c, buffer);
587 if (rc)
588 return rc;
589 if (c == '0' || c == 'n' || c == 'N')
590 cifsFYI = 0;
591 else if (c == '1' || c == 'y' || c == 'Y')
592 cifsFYI = 1;
Steve French1047abc2005-10-11 19:58:06 -0700593 else if((c > '1') && (c <= '9'))
594 cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
596 return count;
597}
598
599static int
600oplockEnabled_read(char *page, char **start, off_t off,
601 int count, int *eof, void *data)
602{
603 int len;
604
605 len = sprintf(page, "%d\n", oplockEnabled);
606
607 len -= off;
608 *start = page + off;
609
610 if (len > count)
611 len = count;
612 else
613 *eof = 1;
614
615 if (len < 0)
616 len = 0;
617
618 return len;
619}
620static int
621oplockEnabled_write(struct file *file, const char __user *buffer,
622 unsigned long count, void *data)
623{
624 char c;
625 int rc;
626
627 rc = get_user(c, buffer);
628 if (rc)
629 return rc;
630 if (c == '0' || c == 'n' || c == 'N')
631 oplockEnabled = 0;
632 else if (c == '1' || c == 'y' || c == 'Y')
633 oplockEnabled = 1;
634
635 return count;
636}
637
638static int
Steve Frenchec637e32005-12-12 20:53:18 -0800639experimEnabled_read(char *page, char **start, off_t off,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 int count, int *eof, void *data)
641{
642 int len;
643
644 len = sprintf(page, "%d\n", experimEnabled);
Steve Frenchec637e32005-12-12 20:53:18 -0800645
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 len -= off;
647 *start = page + off;
648
649 if (len > count)
650 len = count;
651 else
652 *eof = 1;
653
654 if (len < 0)
655 len = 0;
656
657 return len;
658}
659static int
Steve Frenchec637e32005-12-12 20:53:18 -0800660experimEnabled_write(struct file *file, const char __user *buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 unsigned long count, void *data)
662{
Steve Frenchec637e32005-12-12 20:53:18 -0800663 char c;
664 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
Steve Frenchec637e32005-12-12 20:53:18 -0800666 rc = get_user(c, buffer);
667 if (rc)
668 return rc;
669 if (c == '0' || c == 'n' || c == 'N')
670 experimEnabled = 0;
671 else if (c == '1' || c == 'y' || c == 'Y')
672 experimEnabled = 1;
673 else if (c == '2')
674 experimEnabled = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675
Steve Frenchec637e32005-12-12 20:53:18 -0800676 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677}
678
679static int
680linuxExtensionsEnabled_read(char *page, char **start, off_t off,
681 int count, int *eof, void *data)
682{
683 int len;
684
685 len = sprintf(page, "%d\n", linuxExtEnabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 len -= off;
687 *start = page + off;
688
689 if (len > count)
690 len = count;
691 else
692 *eof = 1;
693
694 if (len < 0)
695 len = 0;
696
697 return len;
698}
699static int
700linuxExtensionsEnabled_write(struct file *file, const char __user *buffer,
701 unsigned long count, void *data)
702{
703 char c;
704 int rc;
705
706 rc = get_user(c, buffer);
707 if (rc)
708 return rc;
709 if (c == '0' || c == 'n' || c == 'N')
710 linuxExtEnabled = 0;
711 else if (c == '1' || c == 'y' || c == 'Y')
712 linuxExtEnabled = 1;
713
714 return count;
715}
716
717
718static int
719lookupFlag_read(char *page, char **start, off_t off,
720 int count, int *eof, void *data)
721{
722 int len;
723
724 len = sprintf(page, "%d\n", lookupCacheEnabled);
725
726 len -= off;
727 *start = page + off;
728
729 if (len > count)
730 len = count;
731 else
732 *eof = 1;
733
734 if (len < 0)
735 len = 0;
736
737 return len;
738}
739static int
740lookupFlag_write(struct file *file, const char __user *buffer,
741 unsigned long count, void *data)
742{
743 char c;
744 int rc;
745
746 rc = get_user(c, buffer);
747 if (rc)
748 return rc;
749 if (c == '0' || c == 'n' || c == 'N')
750 lookupCacheEnabled = 0;
751 else if (c == '1' || c == 'y' || c == 'Y')
752 lookupCacheEnabled = 1;
753
754 return count;
755}
756static int
757traceSMB_read(char *page, char **start, off_t off, int count,
758 int *eof, void *data)
759{
760 int len;
761
762 len = sprintf(page, "%d\n", traceSMB);
763
764 len -= off;
765 *start = page + off;
766
767 if (len > count)
768 len = count;
769 else
770 *eof = 1;
771
772 if (len < 0)
773 len = 0;
774
775 return len;
776}
777static int
778traceSMB_write(struct file *file, const char __user *buffer,
779 unsigned long count, void *data)
780{
781 char c;
782 int rc;
783
784 rc = get_user(c, buffer);
785 if (rc)
786 return rc;
787 if (c == '0' || c == 'n' || c == 'N')
788 traceSMB = 0;
789 else if (c == '1' || c == 'y' || c == 'Y')
790 traceSMB = 1;
791
792 return count;
793}
794
795static int
796multiuser_mount_read(char *page, char **start, off_t off,
797 int count, int *eof, void *data)
798{
799 int len;
800
801 len = sprintf(page, "%d\n", multiuser_mount);
802
803 len -= off;
804 *start = page + off;
805
806 if (len > count)
807 len = count;
808 else
809 *eof = 1;
810
811 if (len < 0)
812 len = 0;
813
814 return len;
815}
816static int
817multiuser_mount_write(struct file *file, const char __user *buffer,
818 unsigned long count, void *data)
819{
820 char c;
821 int rc;
822
823 rc = get_user(c, buffer);
824 if (rc)
825 return rc;
826 if (c == '0' || c == 'n' || c == 'N')
827 multiuser_mount = 0;
828 else if (c == '1' || c == 'y' || c == 'Y')
829 multiuser_mount = 1;
830
831 return count;
832}
833
834static int
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000835security_flags_read(char *page, char **start, off_t off,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836 int count, int *eof, void *data)
837{
838 int len;
839
Steve French39798772006-05-31 22:40:51 +0000840 len = sprintf(page, "0x%x\n", extended_security);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
842 len -= off;
843 *start = page + off;
844
845 if (len > count)
846 len = count;
847 else
848 *eof = 1;
849
850 if (len < 0)
851 len = 0;
852
853 return len;
854}
855static int
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000856security_flags_write(struct file *file, const char __user *buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 unsigned long count, void *data)
858{
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000859 unsigned int flags;
860 char flags_string[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 char c;
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000862
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000863 if((count < 1) || (count > 11))
Steve French39798772006-05-31 22:40:51 +0000864 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000866 memset(flags_string, 0, 12);
Steve French39798772006-05-31 22:40:51 +0000867
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000868 if(copy_from_user(flags_string, buffer, count))
869 return -EFAULT;
Steve French39798772006-05-31 22:40:51 +0000870
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000871 if(count < 3) {
872 /* single char or single char followed by null */
873 c = flags_string[0];
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;
878 return count;
879 }
880 /* else we have a number */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000882 flags = simple_strtoul(flags_string, NULL, 0);
883
Steve French9312f672006-06-04 22:21:07 +0000884 cFYI(1,("sec flags 0x%x", flags));
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000885
886 if(flags <= 0) {
887 cERROR(1,("invalid security flags %s",flags_string));
888 return -EINVAL;
889 }
890
Steve French9312f672006-06-04 22:21:07 +0000891 if(flags & ~CIFSSEC_MASK) {
Steve Frencha8ee0342006-06-05 23:34:19 +0000892 cERROR(1,("attempt to set unsupported security flags 0x%x",
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000893 flags & ~CIFSSEC_MASK));
894 return -EINVAL;
895 }
896 /* flags look ok - update the global security flags for cifs module */
897 extended_security = flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 return count;
899}
900
Steve French39798772006-05-31 22:40:51 +0000901/* static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902ntlmv2_enabled_read(char *page, char **start, off_t off,
903 int count, int *eof, void *data)
904{
905 int len;
906
907 len = sprintf(page, "%d\n", ntlmv2_support);
908
909 len -= off;
910 *start = page + off;
911
912 if (len > count)
913 len = count;
914 else
915 *eof = 1;
916
917 if (len < 0)
918 len = 0;
919
920 return len;
921}
922static int
923ntlmv2_enabled_write(struct file *file, const char __user *buffer,
924 unsigned long count, void *data)
925{
926 char c;
927 int rc;
928
929 rc = get_user(c, buffer);
930 if (rc)
931 return rc;
932 if (c == '0' || c == 'n' || c == 'N')
933 ntlmv2_support = 0;
934 else if (c == '1' || c == 'y' || c == 'Y')
935 ntlmv2_support = 1;
Steve French39798772006-05-31 22:40:51 +0000936 else if (c == '2')
937 ntlmv2_support = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
939 return count;
940}
941
942static int
943packet_signing_enabled_read(char *page, char **start, off_t off,
944 int count, int *eof, void *data)
945{
946 int len;
947
948 len = sprintf(page, "%d\n", sign_CIFS_PDUs);
949
950 len -= off;
951 *start = page + off;
952
953 if (len > count)
954 len = count;
955 else
956 *eof = 1;
957
958 if (len < 0)
959 len = 0;
960
961 return len;
962}
963static int
964packet_signing_enabled_write(struct file *file, const char __user *buffer,
965 unsigned long count, void *data)
966{
967 char c;
968 int rc;
969
970 rc = get_user(c, buffer);
971 if (rc)
972 return rc;
973 if (c == '0' || c == 'n' || c == 'N')
974 sign_CIFS_PDUs = 0;
975 else if (c == '1' || c == 'y' || c == 'Y')
976 sign_CIFS_PDUs = 1;
977 else if (c == '2')
978 sign_CIFS_PDUs = 2;
979
980 return count;
Steve French39798772006-05-31 22:40:51 +0000981} */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
983
984#endif