blob: 73c4c419663c1dc1a3558d2df405fcb58bc07e66 [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
Steve French221601c2007-06-05 20:35:06 +000010 * the Free Software Foundation; either version 2 of the License, or
Linus Torvalds1da177e2005-04-16 15:20:36 -070011 * (at your option) any later version.
Steve French221601c2007-06-05 20:35:06 +000012 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * 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
Steve French221601c2007-06-05 20:35:06 +000019 * along with this program; if not, write to the Free Software
Linus Torvalds1da177e2005-04-16 15:20:36 -070020 * 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 French221601c2007-06-05 20:35:06 +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
Steve Frenchffdd6e42007-06-24 21:15:44 +000061void cifs_dump_detail(struct smb_hdr *smb)
Steve French39798772006-05-31 22:40:51 +000062{
Steve French221601c2007-06-05 20:35:06 +000063 cERROR(1, ("Cmd: %d Err: 0x%x Flags: 0x%x Flgs2: 0x%x Mid: %d Pid: %d",
Steve French39798772006-05-31 22:40:51 +000064 smb->Command, smb->Status.CifsError,
65 smb->Flags, smb->Flags2, smb->Mid, smb->Pid));
Steve French221601c2007-06-05 20:35:06 +000066 cERROR(1, ("smb buf %p len %d", smb, smbCalcSize_LE(smb)));
Steve French39798772006-05-31 22:40:51 +000067}
68
69
Steve Frenchffdd6e42007-06-24 21:15:44 +000070void cifs_dump_mids(struct TCP_Server_Info *server)
Steve French39798772006-05-31 22:40:51 +000071{
72 struct list_head *tmp;
Steve Frenchffdd6e42007-06-24 21:15:44 +000073 struct mid_q_entry *mid_entry;
Steve French39798772006-05-31 22:40:51 +000074
Steve French221601c2007-06-05 20:35:06 +000075 if (server == NULL)
Steve French39798772006-05-31 22:40:51 +000076 return;
77
Steve French221601c2007-06-05 20:35:06 +000078 cERROR(1, ("Dump pending requests:"));
Steve French39798772006-05-31 22:40:51 +000079 spin_lock(&GlobalMid_Lock);
80 list_for_each(tmp, &server->pending_mid_q) {
81 mid_entry = list_entry(tmp, struct mid_q_entry, qhead);
Steve French221601c2007-06-05 20:35:06 +000082 if (mid_entry) {
83 cERROR(1, ("State: %d Cmd: %d Pid: %d Tsk: %p Mid %d",
Steve French39798772006-05-31 22:40:51 +000084 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
Steve French221601c2007-06-05 20:35:06 +000090 cERROR(1, ("IsLarge: %d buf: %p time rcv: %ld now: %ld",
Steve French39798772006-05-31 22:40:51 +000091 mid_entry->largeBuf,
92 mid_entry->resp_buf,
93 mid_entry->when_received,
94 jiffies));
95#endif /* STATS2 */
Steve French221601c2007-06-05 20:35:06 +000096 cERROR(1, ("IsMult: %d IsEnd: %d", mid_entry->multiRsp,
Steve French39798772006-05-31 22:40:51 +000097 mid_entry->multiEnd));
Steve French221601c2007-06-05 20:35:06 +000098 if (mid_entry->resp_buf) {
Steve French39798772006-05-31 22:40:51 +000099 cifs_dump_detail(mid_entry->resp_buf);
100 cifs_dump_mem("existing buf: ",
101 mid_entry->resp_buf,
102 62 /* fixme */);
103 }
Steve French39798772006-05-31 22:40:51 +0000104 }
105 }
106 spin_unlock(&GlobalMid_Lock);
107}
108#endif /* CONFIG_CIFS_DEBUG2 */
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110#ifdef CONFIG_PROC_FS
111static int
112cifs_debug_data_read(char *buf, char **beginBuffer, off_t offset,
113 int count, int *eof, void *data)
114{
115 struct list_head *tmp;
116 struct list_head *tmp1;
Steve Frenchffdd6e42007-06-24 21:15:44 +0000117 struct mid_q_entry *mid_entry;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 struct cifsSesInfo *ses;
119 struct cifsTconInfo *tcon;
120 int i;
121 int length = 0;
Steve Frenchffdd6e42007-06-24 21:15:44 +0000122 char *original_buf = buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123
124 *beginBuffer = buf + offset;
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 length =
127 sprintf(buf,
128 "Display Internal CIFS Data Structures for Debugging\n"
129 "---------------------------------------------------\n");
130 buf += length;
Steve French221601c2007-06-05 20:35:06 +0000131 length = sprintf(buf, "CIFS Version %s\n", CIFS_VERSION);
Steve French6c91d362005-04-28 22:41:06 -0700132 buf += length;
Steve French221601c2007-06-05 20:35:06 +0000133 length = sprintf(buf,
134 "Active VFS Requests: %d\n", GlobalTotalActiveXid);
Steve French131afd0b2005-10-07 09:51:05 -0700135 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 French221601c2007-06-05 20:35:06 +0000144 if ((ses->serverDomain == NULL) || (ses->serverOS == NULL) ||
Steve French433dc242005-04-28 22:41:08 -0700145 (ses->serverNOS == NULL)) {
Steve Frenchbd2abf12007-01-21 23:19:01 +0000146 buf += sprintf(buf, "\nentry for %s not fully "
147 "displayed\n\t", ses->serverName);
Steve French433dc242005-04-28 22:41:08 -0700148 } else {
149 length =
150 sprintf(buf,
Steve French221601c2007-06-05 20:35:06 +0000151 "\n%d) Name: %s Domain: %s Mounts: %d OS:"
152 " %s \n\tNOS: %s\tCapability: 0x%x\n\tSMB"
153 " session status: %d\t",
Steve Frenchb8643e12005-04-28 22:41:07 -0700154 i, ses->serverName, ses->serverDomain,
155 atomic_read(&ses->inUse),
156 ses->serverOS, ses->serverNOS,
Steve French221601c2007-06-05 20:35:06 +0000157 ses->capabilities, ses->status);
Steve French433dc242005-04-28 22:41:08 -0700158 buf += length;
159 }
Steve French221601c2007-06-05 20:35:06 +0000160 if (ses->server) {
161 buf += sprintf(buf, "TCP status: %d\n\tLocal Users To "
162 "Server: %d SecMode: 0x%x Req On Wire: %d",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 ses->server->tcpStatus,
164 atomic_read(&ses->server->socketUseCount),
165 ses->server->secMode,
166 atomic_read(&ses->server->inFlight));
Steve French131afd0b2005-10-07 09:51:05 -0700167
168#ifdef CONFIG_CIFS_STATS2
Steve French68058e72005-10-10 10:34:22 -0700169 buf += sprintf(buf, " In Send: %d In MaxReq Wait: %d",
Steve French221601c2007-06-05 20:35:06 +0000170 atomic_read(&ses->server->inSend),
Steve French131afd0b2005-10-07 09:51:05 -0700171 atomic_read(&ses->server->num_waiters));
172#endif
173
Steve French6c91d362005-04-28 22:41:06 -0700174 length = sprintf(buf, "\nMIDs:\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 buf += length;
176
177 spin_lock(&GlobalMid_Lock);
178 list_for_each(tmp1, &ses->server->pending_mid_q) {
179 mid_entry = list_entry(tmp1, struct
180 mid_q_entry,
181 qhead);
Steve French221601c2007-06-05 20:35:06 +0000182 if (mid_entry) {
183 length = sprintf(buf,
184 "State: %d com: %d pid:"
185 " %d tsk: %p mid %d\n",
186 mid_entry->midState,
187 (int)mid_entry->command,
188 mid_entry->pid,
189 mid_entry->tsk,
190 mid_entry->mid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 buf += length;
192 }
193 }
Steve French221601c2007-06-05 20:35:06 +0000194 spin_unlock(&GlobalMid_Lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 }
196
197 }
198 read_unlock(&GlobalSMBSeslock);
199 sprintf(buf, "\n");
200 buf++;
201
Steve French6c91d362005-04-28 22:41:06 -0700202 length = sprintf(buf, "Shares:");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 buf += length;
204
205 i = 0;
206 read_lock(&GlobalSMBSeslock);
207 list_for_each(tmp, &GlobalTreeConnectionList) {
208 __u32 dev_type;
209 i++;
210 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
211 dev_type = le32_to_cpu(tcon->fsDevInfo.DeviceType);
Steve French88f370a2007-09-15 03:01:17 +0000212 length = sprintf(buf, "\n%d) %s Uses: %d ", i,
213 tcon->treeName, atomic_read(&tcon->useCount));
214 buf += length;
215 if (tcon->nativeFileSystem) {
Steve Frencha23d3062007-09-15 03:43:47 +0000216 length = sprintf(buf, "Type: %s ",
217 tcon->nativeFileSystem);
Steve French88f370a2007-09-15 03:01:17 +0000218 buf += length;
219 }
220 length = sprintf(buf, "DevInfo: 0x%x Attributes: 0x%x"
221 "\nPathComponentMax: %d Status: %d",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 le32_to_cpu(tcon->fsDevInfo.DeviceCharacteristics),
223 le32_to_cpu(tcon->fsAttrInfo.Attributes),
224 le32_to_cpu(tcon->fsAttrInfo.MaxPathNameComponentLength),
225 tcon->tidStatus);
Steve French221601c2007-06-05 20:35:06 +0000226 buf += length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 if (dev_type == FILE_DEVICE_DISK)
228 length = sprintf(buf, " type: DISK ");
229 else if (dev_type == FILE_DEVICE_CD_ROM)
230 length = sprintf(buf, " type: CDROM ");
231 else
232 length =
233 sprintf(buf, " type: %d ", dev_type);
234 buf += length;
Steve French221601c2007-06-05 20:35:06 +0000235 if (tcon->tidStatus == CifsNeedReconnect) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236 buf += sprintf(buf, "\tDISCONNECTED ");
237 length += 14;
238 }
239 }
240 read_unlock(&GlobalSMBSeslock);
241
242 length = sprintf(buf, "\n");
243 buf += length;
244
245 /* BB add code to dump additional info such as TCP session info now */
246 /* Now calculate total size of returned data */
247 length = buf - original_buf;
248
Steve French221601c2007-06-05 20:35:06 +0000249 if (offset + count >= length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250 *eof = 1;
Steve French221601c2007-06-05 20:35:06 +0000251 if (length < offset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 *eof = 1;
253 return 0;
254 } else {
255 length = length - offset;
256 }
257 if (length > count)
258 length = count;
259
260 return length;
261}
262
263#ifdef CONFIG_CIFS_STATS
Steve French1047abc2005-10-11 19:58:06 -0700264
265static int
266cifs_stats_write(struct file *file, const char __user *buffer,
Steve French221601c2007-06-05 20:35:06 +0000267 unsigned long count, void *data)
Steve French1047abc2005-10-11 19:58:06 -0700268{
Steve French221601c2007-06-05 20:35:06 +0000269 char c;
270 int rc;
Steve French1047abc2005-10-11 19:58:06 -0700271 struct list_head *tmp;
272 struct cifsTconInfo *tcon;
273
Steve French221601c2007-06-05 20:35:06 +0000274 rc = get_user(c, buffer);
275 if (rc)
276 return rc;
Steve French1047abc2005-10-11 19:58:06 -0700277
Steve French221601c2007-06-05 20:35:06 +0000278 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
Steve French1047abc2005-10-11 19:58:06 -0700279 read_lock(&GlobalSMBSeslock);
Steve French4498eed52005-12-03 13:58:57 -0800280#ifdef CONFIG_CIFS_STATS2
281 atomic_set(&totBufAllocCount, 0);
282 atomic_set(&totSmBufAllocCount, 0);
283#endif /* CONFIG_CIFS_STATS2 */
Steve French1047abc2005-10-11 19:58:06 -0700284 list_for_each(tmp, &GlobalTreeConnectionList) {
285 tcon = list_entry(tmp, struct cifsTconInfo,
286 cifsConnectionList);
287 atomic_set(&tcon->num_smbs_sent, 0);
288 atomic_set(&tcon->num_writes, 0);
289 atomic_set(&tcon->num_reads, 0);
290 atomic_set(&tcon->num_oplock_brks, 0);
291 atomic_set(&tcon->num_opens, 0);
292 atomic_set(&tcon->num_closes, 0);
293 atomic_set(&tcon->num_deletes, 0);
294 atomic_set(&tcon->num_mkdirs, 0);
295 atomic_set(&tcon->num_rmdirs, 0);
296 atomic_set(&tcon->num_renames, 0);
297 atomic_set(&tcon->num_t2renames, 0);
298 atomic_set(&tcon->num_ffirst, 0);
299 atomic_set(&tcon->num_fnext, 0);
300 atomic_set(&tcon->num_fclose, 0);
301 atomic_set(&tcon->num_hardlinks, 0);
302 atomic_set(&tcon->num_symlinks, 0);
303 atomic_set(&tcon->num_locks, 0);
304 }
305 read_unlock(&GlobalSMBSeslock);
306 }
307
Steve French221601c2007-06-05 20:35:06 +0000308 return count;
Steve French1047abc2005-10-11 19:58:06 -0700309}
310
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311static int
312cifs_stats_read(char *buf, char **beginBuffer, off_t offset,
313 int count, int *eof, void *data)
314{
Steve French221601c2007-06-05 20:35:06 +0000315 int item_length, i, length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 struct list_head *tmp;
317 struct cifsTconInfo *tcon;
318
319 *beginBuffer = buf + offset;
320
321 length = sprintf(buf,
322 "Resources in use\nCIFS Session: %d\n",
323 sesInfoAllocCount.counter);
324 buf += length;
Steve French221601c2007-06-05 20:35:06 +0000325 item_length =
326 sprintf(buf, "Share (unique mount targets): %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 tconInfoAllocCount.counter);
328 length += item_length;
Steve French221601c2007-06-05 20:35:06 +0000329 buf += item_length;
330 item_length =
331 sprintf(buf, "SMB Request/Response Buffer: %d Pool size: %d\n",
Steve Frenchb8643e12005-04-28 22:41:07 -0700332 bufAllocCount.counter,
333 cifs_min_rcv + tcpSesAllocCount.counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 length += item_length;
335 buf += item_length;
Steve French221601c2007-06-05 20:35:06 +0000336 item_length =
337 sprintf(buf, "SMB Small Req/Resp Buffer: %d Pool size: %d\n",
338 smBufAllocCount.counter, cifs_min_small);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 length += item_length;
340 buf += item_length;
Steve French07475ff2005-12-03 14:11:37 -0800341#ifdef CONFIG_CIFS_STATS2
Steve French221601c2007-06-05 20:35:06 +0000342 item_length = sprintf(buf, "Total Large %d Small %d Allocations\n",
Steve French07475ff2005-12-03 14:11:37 -0800343 atomic_read(&totBufAllocCount),
Steve French221601c2007-06-05 20:35:06 +0000344 atomic_read(&totSmBufAllocCount));
Steve French07475ff2005-12-03 14:11:37 -0800345 length += item_length;
346 buf += item_length;
347#endif /* CONFIG_CIFS_STATS2 */
348
Steve French221601c2007-06-05 20:35:06 +0000349 item_length =
350 sprintf(buf, "Operations (MIDs): %d\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 midCount.counter);
352 length += item_length;
353 buf += item_length;
354 item_length = sprintf(buf,
355 "\n%d session %d share reconnects\n",
Steve French221601c2007-06-05 20:35:06 +0000356 tcpSesReconnectCount.counter, tconInfoReconnectCount.counter);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 length += item_length;
358 buf += item_length;
359
360 item_length = sprintf(buf,
361 "Total vfs operations: %d maximum at one time: %d\n",
Steve French221601c2007-06-05 20:35:06 +0000362 GlobalCurrentXid, GlobalMaxActiveXid);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 length += item_length;
364 buf += item_length;
365
366 i = 0;
367 read_lock(&GlobalSMBSeslock);
368 list_for_each(tmp, &GlobalTreeConnectionList) {
369 i++;
370 tcon = list_entry(tmp, struct cifsTconInfo, cifsConnectionList);
Steve French221601c2007-06-05 20:35:06 +0000371 item_length = sprintf(buf, "\n%d) %s", i, tcon->treeName);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 buf += item_length;
373 length += item_length;
Steve French221601c2007-06-05 20:35:06 +0000374 if (tcon->tidStatus == CifsNeedReconnect) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 buf += sprintf(buf, "\tDISCONNECTED ");
376 length += 14;
377 }
Steve Frencha5a2b482005-08-20 21:42:53 -0700378 item_length = sprintf(buf, "\nSMBs: %d Oplock Breaks: %d",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 atomic_read(&tcon->num_smbs_sent),
380 atomic_read(&tcon->num_oplock_brks));
381 buf += item_length;
382 length += item_length;
Steve French0ae0efa2005-10-10 10:57:19 -0700383 item_length = sprintf(buf, "\nReads: %d Bytes: %lld",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 atomic_read(&tcon->num_reads),
385 (long long)(tcon->bytes_read));
386 buf += item_length;
387 length += item_length;
Steve Frencha5a2b482005-08-20 21:42:53 -0700388 item_length = sprintf(buf, "\nWrites: %d Bytes: %lld",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 atomic_read(&tcon->num_writes),
390 (long long)(tcon->bytes_written));
Steve French221601c2007-06-05 20:35:06 +0000391 buf += item_length;
392 length += item_length;
393 item_length = sprintf(buf,
Steve Frencha5a2b482005-08-20 21:42:53 -0700394 "\nLocks: %d HardLinks: %d Symlinks: %d",
Steve French221601c2007-06-05 20:35:06 +0000395 atomic_read(&tcon->num_locks),
Steve Frencha5a2b482005-08-20 21:42:53 -0700396 atomic_read(&tcon->num_hardlinks),
397 atomic_read(&tcon->num_symlinks));
Steve French221601c2007-06-05 20:35:06 +0000398 buf += item_length;
399 length += item_length;
Steve Frencha5a2b482005-08-20 21:42:53 -0700400
401 item_length = sprintf(buf, "\nOpens: %d Closes: %d Deletes: %d",
402 atomic_read(&tcon->num_opens),
403 atomic_read(&tcon->num_closes),
404 atomic_read(&tcon->num_deletes));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 buf += item_length;
406 length += item_length;
Steve Frencha5a2b482005-08-20 21:42:53 -0700407 item_length = sprintf(buf, "\nMkdirs: %d Rmdirs: %d",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408 atomic_read(&tcon->num_mkdirs),
409 atomic_read(&tcon->num_rmdirs));
410 buf += item_length;
411 length += item_length;
Steve Frencha5a2b482005-08-20 21:42:53 -0700412 item_length = sprintf(buf, "\nRenames: %d T2 Renames %d",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 atomic_read(&tcon->num_renames),
414 atomic_read(&tcon->num_t2renames));
415 buf += item_length;
416 length += item_length;
Steve Frencha5a2b482005-08-20 21:42:53 -0700417 item_length = sprintf(buf, "\nFindFirst: %d FNext %d FClose %d",
Steve French0c0ff092005-06-23 19:31:17 -0500418 atomic_read(&tcon->num_ffirst),
419 atomic_read(&tcon->num_fnext),
420 atomic_read(&tcon->num_fclose));
421 buf += item_length;
422 length += item_length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423 }
424 read_unlock(&GlobalSMBSeslock);
425
Steve French221601c2007-06-05 20:35:06 +0000426 buf += sprintf(buf, "\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 length++;
428
Steve French221601c2007-06-05 20:35:06 +0000429 if (offset + count >= length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 *eof = 1;
Steve French221601c2007-06-05 20:35:06 +0000431 if (length < offset) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 *eof = 1;
433 return 0;
434 } else {
435 length = length - offset;
436 }
437 if (length > count)
438 length = count;
Steve French221601c2007-06-05 20:35:06 +0000439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 return length;
441}
442#endif
443
444static struct proc_dir_entry *proc_fs_cifs;
445read_proc_t cifs_txanchor_read;
446static read_proc_t cifsFYI_read;
447static write_proc_t cifsFYI_write;
448static read_proc_t oplockEnabled_read;
449static write_proc_t oplockEnabled_write;
450static read_proc_t lookupFlag_read;
451static write_proc_t lookupFlag_write;
452static read_proc_t traceSMB_read;
453static write_proc_t traceSMB_write;
454static read_proc_t multiuser_mount_read;
455static write_proc_t multiuser_mount_write;
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000456static read_proc_t security_flags_read;
457static write_proc_t security_flags_write;
Steve French39798772006-05-31 22:40:51 +0000458/* static read_proc_t ntlmv2_enabled_read;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459static write_proc_t ntlmv2_enabled_write;
460static read_proc_t packet_signing_enabled_read;
Steve French39798772006-05-31 22:40:51 +0000461static write_proc_t packet_signing_enabled_write;*/
Steve Frenchec637e32005-12-12 20:53:18 -0800462static read_proc_t experimEnabled_read;
463static write_proc_t experimEnabled_write;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464static read_proc_t linuxExtensionsEnabled_read;
465static write_proc_t linuxExtensionsEnabled_write;
466
467void
468cifs_proc_init(void)
469{
470 struct proc_dir_entry *pde;
471
472 proc_fs_cifs = proc_mkdir("cifs", proc_root_fs);
473 if (proc_fs_cifs == NULL)
474 return;
475
476 proc_fs_cifs->owner = THIS_MODULE;
477 create_proc_read_entry("DebugData", 0, proc_fs_cifs,
478 cifs_debug_data_read, NULL);
479
480#ifdef CONFIG_CIFS_STATS
Steve French1047abc2005-10-11 19:58:06 -0700481 pde = create_proc_read_entry("Stats", 0, proc_fs_cifs,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 cifs_stats_read, NULL);
Steve French1047abc2005-10-11 19:58:06 -0700483 if (pde)
484 pde->write_proc = cifs_stats_write;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485#endif
486 pde = create_proc_read_entry("cifsFYI", 0, proc_fs_cifs,
487 cifsFYI_read, NULL);
488 if (pde)
489 pde->write_proc = cifsFYI_write;
490
491 pde =
492 create_proc_read_entry("traceSMB", 0, proc_fs_cifs,
493 traceSMB_read, NULL);
494 if (pde)
495 pde->write_proc = traceSMB_write;
496
497 pde = create_proc_read_entry("OplockEnabled", 0, proc_fs_cifs,
498 oplockEnabled_read, NULL);
499 if (pde)
500 pde->write_proc = oplockEnabled_write;
501
Steve French0c0ff092005-06-23 19:31:17 -0500502 pde = create_proc_read_entry("Experimental", 0, proc_fs_cifs,
Steve Frenchec637e32005-12-12 20:53:18 -0800503 experimEnabled_read, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 if (pde)
Steve Frenchec637e32005-12-12 20:53:18 -0800505 pde->write_proc = experimEnabled_write;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
507 pde = create_proc_read_entry("LinuxExtensionsEnabled", 0, proc_fs_cifs,
508 linuxExtensionsEnabled_read, NULL);
509 if (pde)
510 pde->write_proc = linuxExtensionsEnabled_write;
511
512 pde =
513 create_proc_read_entry("MultiuserMount", 0, proc_fs_cifs,
514 multiuser_mount_read, NULL);
515 if (pde)
516 pde->write_proc = multiuser_mount_write;
517
518 pde =
Steve French7c7b25b2006-06-01 19:20:10 +0000519 create_proc_read_entry("SecurityFlags", 0, proc_fs_cifs,
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000520 security_flags_read, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 if (pde)
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000522 pde->write_proc = security_flags_write;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
524 pde =
525 create_proc_read_entry("LookupCacheEnabled", 0, proc_fs_cifs,
526 lookupFlag_read, NULL);
527 if (pde)
528 pde->write_proc = lookupFlag_write;
529
Steve French39798772006-05-31 22:40:51 +0000530/* pde =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 create_proc_read_entry("NTLMV2Enabled", 0, proc_fs_cifs,
532 ntlmv2_enabled_read, NULL);
533 if (pde)
534 pde->write_proc = ntlmv2_enabled_write;
535
536 pde =
537 create_proc_read_entry("PacketSigningEnabled", 0, proc_fs_cifs,
538 packet_signing_enabled_read, NULL);
539 if (pde)
Steve French39798772006-05-31 22:40:51 +0000540 pde->write_proc = packet_signing_enabled_write;*/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541}
542
543void
544cifs_proc_clean(void)
545{
546 if (proc_fs_cifs == NULL)
547 return;
548
549 remove_proc_entry("DebugData", proc_fs_cifs);
550 remove_proc_entry("cifsFYI", proc_fs_cifs);
551 remove_proc_entry("traceSMB", proc_fs_cifs);
552#ifdef CONFIG_CIFS_STATS
553 remove_proc_entry("Stats", proc_fs_cifs);
554#endif
555 remove_proc_entry("MultiuserMount", proc_fs_cifs);
556 remove_proc_entry("OplockEnabled", proc_fs_cifs);
Steve French39798772006-05-31 22:40:51 +0000557/* remove_proc_entry("NTLMV2Enabled",proc_fs_cifs); */
Steve French221601c2007-06-05 20:35:06 +0000558 remove_proc_entry("SecurityFlags", proc_fs_cifs);
559/* remove_proc_entry("PacketSigningEnabled", proc_fs_cifs); */
560 remove_proc_entry("LinuxExtensionsEnabled", proc_fs_cifs);
561 remove_proc_entry("Experimental", proc_fs_cifs);
562 remove_proc_entry("LookupCacheEnabled", proc_fs_cifs);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 remove_proc_entry("cifs", proc_root_fs);
564}
565
566static int
567cifsFYI_read(char *page, char **start, off_t off, int count,
568 int *eof, void *data)
569{
570 int len;
571
572 len = sprintf(page, "%d\n", cifsFYI);
573
574 len -= off;
575 *start = page + off;
576
577 if (len > count)
578 len = count;
579 else
580 *eof = 1;
581
582 if (len < 0)
583 len = 0;
584
585 return len;
586}
587static int
588cifsFYI_write(struct file *file, const char __user *buffer,
589 unsigned long count, void *data)
590{
591 char c;
592 int rc;
593
594 rc = get_user(c, buffer);
595 if (rc)
596 return rc;
597 if (c == '0' || c == 'n' || c == 'N')
598 cifsFYI = 0;
599 else if (c == '1' || c == 'y' || c == 'Y')
600 cifsFYI = 1;
Steve French221601c2007-06-05 20:35:06 +0000601 else if ((c > '1') && (c <= '9'))
Steve French1047abc2005-10-11 19:58:06 -0700602 cifsFYI = (int) (c - '0'); /* see cifs_debug.h for meanings */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603
604 return count;
605}
606
607static int
608oplockEnabled_read(char *page, char **start, off_t off,
609 int count, int *eof, void *data)
610{
611 int len;
612
613 len = sprintf(page, "%d\n", oplockEnabled);
614
615 len -= off;
616 *start = page + off;
617
618 if (len > count)
619 len = count;
620 else
621 *eof = 1;
622
623 if (len < 0)
624 len = 0;
625
626 return len;
627}
628static int
629oplockEnabled_write(struct file *file, const char __user *buffer,
630 unsigned long count, void *data)
631{
632 char c;
633 int rc;
634
635 rc = get_user(c, buffer);
636 if (rc)
637 return rc;
638 if (c == '0' || c == 'n' || c == 'N')
639 oplockEnabled = 0;
640 else if (c == '1' || c == 'y' || c == 'Y')
641 oplockEnabled = 1;
642
643 return count;
644}
645
646static int
Steve Frenchec637e32005-12-12 20:53:18 -0800647experimEnabled_read(char *page, char **start, off_t off,
Steve French221601c2007-06-05 20:35:06 +0000648 int count, int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649{
Steve French221601c2007-06-05 20:35:06 +0000650 int len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
Steve French221601c2007-06-05 20:35:06 +0000652 len = sprintf(page, "%d\n", experimEnabled);
Steve Frenchec637e32005-12-12 20:53:18 -0800653
Steve French221601c2007-06-05 20:35:06 +0000654 len -= off;
655 *start = page + off;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656
Steve French221601c2007-06-05 20:35:06 +0000657 if (len > count)
658 len = count;
659 else
660 *eof = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661
Steve French221601c2007-06-05 20:35:06 +0000662 if (len < 0)
663 len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664
Steve French221601c2007-06-05 20:35:06 +0000665 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666}
667static int
Steve Frenchec637e32005-12-12 20:53:18 -0800668experimEnabled_write(struct file *file, const char __user *buffer,
Steve French221601c2007-06-05 20:35:06 +0000669 unsigned long count, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670{
Steve Frenchec637e32005-12-12 20:53:18 -0800671 char c;
672 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673
Steve Frenchec637e32005-12-12 20:53:18 -0800674 rc = get_user(c, buffer);
675 if (rc)
676 return rc;
677 if (c == '0' || c == 'n' || c == 'N')
678 experimEnabled = 0;
679 else if (c == '1' || c == 'y' || c == 'Y')
680 experimEnabled = 1;
681 else if (c == '2')
682 experimEnabled = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683
Steve Frenchec637e32005-12-12 20:53:18 -0800684 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685}
686
687static int
688linuxExtensionsEnabled_read(char *page, char **start, off_t off,
Steve French221601c2007-06-05 20:35:06 +0000689 int count, int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690{
Steve French221601c2007-06-05 20:35:06 +0000691 int len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
Steve French221601c2007-06-05 20:35:06 +0000693 len = sprintf(page, "%d\n", linuxExtEnabled);
694 len -= off;
695 *start = page + off;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696
Steve French221601c2007-06-05 20:35:06 +0000697 if (len > count)
698 len = count;
699 else
700 *eof = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701
Steve French221601c2007-06-05 20:35:06 +0000702 if (len < 0)
703 len = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704
Steve French221601c2007-06-05 20:35:06 +0000705 return len;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706}
707static int
708linuxExtensionsEnabled_write(struct file *file, const char __user *buffer,
Steve French221601c2007-06-05 20:35:06 +0000709 unsigned long count, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710{
Steve French221601c2007-06-05 20:35:06 +0000711 char c;
712 int rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
Steve French221601c2007-06-05 20:35:06 +0000714 rc = get_user(c, buffer);
715 if (rc)
716 return rc;
717 if (c == '0' || c == 'n' || c == 'N')
718 linuxExtEnabled = 0;
719 else if (c == '1' || c == 'y' || c == 'Y')
720 linuxExtEnabled = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721
Steve French221601c2007-06-05 20:35:06 +0000722 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723}
724
725
726static int
727lookupFlag_read(char *page, char **start, off_t off,
Steve French221601c2007-06-05 20:35:06 +0000728 int count, int *eof, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729{
730 int len;
731
732 len = sprintf(page, "%d\n", lookupCacheEnabled);
733
734 len -= off;
735 *start = page + off;
736
737 if (len > count)
738 len = count;
739 else
740 *eof = 1;
741
742 if (len < 0)
743 len = 0;
744
745 return len;
746}
747static int
748lookupFlag_write(struct file *file, const char __user *buffer,
749 unsigned long count, void *data)
750{
751 char c;
752 int rc;
753
754 rc = get_user(c, buffer);
755 if (rc)
756 return rc;
757 if (c == '0' || c == 'n' || c == 'N')
758 lookupCacheEnabled = 0;
759 else if (c == '1' || c == 'y' || c == 'Y')
760 lookupCacheEnabled = 1;
761
762 return count;
763}
764static int
765traceSMB_read(char *page, char **start, off_t off, int count,
766 int *eof, void *data)
767{
768 int len;
769
770 len = sprintf(page, "%d\n", traceSMB);
771
772 len -= off;
773 *start = page + off;
774
775 if (len > count)
776 len = count;
777 else
778 *eof = 1;
779
780 if (len < 0)
781 len = 0;
782
783 return len;
784}
785static int
786traceSMB_write(struct file *file, const char __user *buffer,
787 unsigned long count, void *data)
788{
789 char c;
790 int rc;
791
792 rc = get_user(c, buffer);
793 if (rc)
794 return rc;
795 if (c == '0' || c == 'n' || c == 'N')
796 traceSMB = 0;
797 else if (c == '1' || c == 'y' || c == 'Y')
798 traceSMB = 1;
799
800 return count;
801}
802
803static int
804multiuser_mount_read(char *page, char **start, off_t off,
805 int count, int *eof, void *data)
806{
807 int len;
808
809 len = sprintf(page, "%d\n", multiuser_mount);
810
811 len -= off;
812 *start = page + off;
813
814 if (len > count)
815 len = count;
816 else
817 *eof = 1;
818
819 if (len < 0)
820 len = 0;
821
822 return len;
823}
824static int
825multiuser_mount_write(struct file *file, const char __user *buffer,
826 unsigned long count, void *data)
827{
828 char c;
829 int rc;
830
831 rc = get_user(c, buffer);
832 if (rc)
833 return rc;
834 if (c == '0' || c == 'n' || c == 'N')
835 multiuser_mount = 0;
836 else if (c == '1' || c == 'y' || c == 'Y')
837 multiuser_mount = 1;
838
839 return count;
840}
841
842static int
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000843security_flags_read(char *page, char **start, off_t off,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844 int count, int *eof, void *data)
845{
846 int len;
847
Steve French39798772006-05-31 22:40:51 +0000848 len = sprintf(page, "0x%x\n", extended_security);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849
850 len -= off;
851 *start = page + off;
852
853 if (len > count)
854 len = count;
855 else
856 *eof = 1;
857
858 if (len < 0)
859 len = 0;
860
861 return len;
862}
863static int
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000864security_flags_write(struct file *file, const char __user *buffer,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 unsigned long count, void *data)
866{
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000867 unsigned int flags;
868 char flags_string[12];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869 char c;
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000870
Steve French221601c2007-06-05 20:35:06 +0000871 if ((count < 1) || (count > 11))
Steve French39798772006-05-31 22:40:51 +0000872 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000874 memset(flags_string, 0, 12);
Steve French39798772006-05-31 22:40:51 +0000875
Steve French221601c2007-06-05 20:35:06 +0000876 if (copy_from_user(flags_string, buffer, count))
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000877 return -EFAULT;
Steve French39798772006-05-31 22:40:51 +0000878
Steve French221601c2007-06-05 20:35:06 +0000879 if (count < 3) {
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000880 /* single char or single char followed by null */
881 c = flags_string[0];
Steve Frencha0136892007-10-04 20:05:09 +0000882 if (c == '0' || c == 'n' || c == 'N') {
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000883 extended_security = CIFSSEC_DEF; /* default */
Steve Frencha0136892007-10-04 20:05:09 +0000884 return count;
885 } else if (c == '1' || c == 'y' || c == 'Y') {
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000886 extended_security = CIFSSEC_MAX;
Steve Frencha0136892007-10-04 20:05:09 +0000887 return count;
888 } else if (!isdigit(c)) {
889 cERROR(1, ("invalid flag %c", c));
890 return -EINVAL;
891 }
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000892 }
893 /* else we have a number */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000895 flags = simple_strtoul(flags_string, NULL, 0);
896
Steve French221601c2007-06-05 20:35:06 +0000897 cFYI(1, ("sec flags 0x%x", flags));
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000898
Steve French221601c2007-06-05 20:35:06 +0000899 if (flags <= 0) {
900 cERROR(1, ("invalid security flags %s", flags_string));
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000901 return -EINVAL;
902 }
903
Steve French221601c2007-06-05 20:35:06 +0000904 if (flags & ~CIFSSEC_MASK) {
905 cERROR(1, ("attempt to set unsupported security flags 0x%x",
Steve Frenchbdc4bf6e2006-06-02 22:57:13 +0000906 flags & ~CIFSSEC_MASK));
907 return -EINVAL;
908 }
909 /* flags look ok - update the global security flags for cifs module */
910 extended_security = flags;
Steve French762e5ab2007-06-28 18:41:42 +0000911 if (extended_security & CIFSSEC_MUST_SIGN) {
912 /* requiring signing implies signing is allowed */
913 extended_security |= CIFSSEC_MAY_SIGN;
914 cFYI(1, ("packet signing now required"));
915 } else if ((extended_security & CIFSSEC_MAY_SIGN) == 0) {
916 cFYI(1, ("packet signing disabled"));
917 }
918 /* BB should we turn on MAY flags for other MUST options? */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 return count;
920}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921#endif