blob: 53dd8e28dd8a026a6dcfed308eeaf66628febfba [file] [log] [blame]
Latchesar Ionkov5174fda2006-03-25 03:07:25 -08001/*
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -05002 * net/9p/fcprint.c
Latchesar Ionkov5174fda2006-03-25 03:07:25 -08003 *
4 * Print 9P call.
5 *
6 * Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net>
7 *
8 * This program is free software; you can redistribute it and/or modify
Eric Van Hensbergen42e8c502006-03-25 03:07:28 -08009 * it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080011 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to:
19 * Free Software Foundation
20 * 51 Franklin Street, Fifth Floor
21 * Boston, MA 02111-1301 USA
22 *
23 */
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080024#include <linux/module.h>
25#include <linux/errno.h>
26#include <linux/fs.h>
27#include <linux/idr.h>
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050028#include <net/9p/9p.h>
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080029
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050030#ifdef CONFIG_NET_9P_DEBUG
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080031
32static int
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050033p9_printqid(char *buf, int buflen, struct p9_qid *q)
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080034{
35 int n;
36 char b[10];
37
38 n = 0;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050039 if (q->type & P9_QTDIR)
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080040 b[n++] = 'd';
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050041 if (q->type & P9_QTAPPEND)
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080042 b[n++] = 'a';
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050043 if (q->type & P9_QTAUTH)
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080044 b[n++] = 'A';
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050045 if (q->type & P9_QTEXCL)
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080046 b[n++] = 'l';
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050047 if (q->type & P9_QTTMP)
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080048 b[n++] = 't';
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050049 if (q->type & P9_QTSYMLINK)
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080050 b[n++] = 'L';
51 b[n] = '\0';
52
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050053 return scnprintf(buf, buflen, "(%.16llx %x %s)",
54 (long long int) q->path, q->version, b);
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080055}
56
57static int
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050058p9_printperm(char *buf, int buflen, int perm)
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080059{
60 int n;
61 char b[15];
62
63 n = 0;
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050064 if (perm & P9_DMDIR)
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080065 b[n++] = 'd';
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050066 if (perm & P9_DMAPPEND)
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080067 b[n++] = 'a';
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050068 if (perm & P9_DMAUTH)
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080069 b[n++] = 'A';
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050070 if (perm & P9_DMEXCL)
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080071 b[n++] = 'l';
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050072 if (perm & P9_DMTMP)
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080073 b[n++] = 't';
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050074 if (perm & P9_DMDEVICE)
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080075 b[n++] = 'D';
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050076 if (perm & P9_DMSOCKET)
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080077 b[n++] = 'S';
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050078 if (perm & P9_DMNAMEDPIPE)
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080079 b[n++] = 'P';
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050080 if (perm & P9_DMSYMLINK)
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080081 b[n++] = 'L';
82 b[n] = '\0';
83
84 return scnprintf(buf, buflen, "%s%03o", b, perm&077);
85}
86
87static int
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -050088p9_printstat(char *buf, int buflen, struct p9_stat *st, int extended)
Latchesar Ionkov5174fda2006-03-25 03:07:25 -080089{
90 int n;
91
92 n = scnprintf(buf, buflen, "'%.*s' '%.*s'", st->name.len,
93 st->name.str, st->uid.len, st->uid.str);
94 if (extended)
95 n += scnprintf(buf+n, buflen-n, "(%d)", st->n_uid);
96
97 n += scnprintf(buf+n, buflen-n, " '%.*s'", st->gid.len, st->gid.str);
98 if (extended)
99 n += scnprintf(buf+n, buflen-n, "(%d)", st->n_gid);
100
101 n += scnprintf(buf+n, buflen-n, " '%.*s'", st->muid.len, st->muid.str);
102 if (extended)
103 n += scnprintf(buf+n, buflen-n, "(%d)", st->n_muid);
104
105 n += scnprintf(buf+n, buflen-n, " q ");
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500106 n += p9_printqid(buf+n, buflen-n, &st->qid);
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800107 n += scnprintf(buf+n, buflen-n, " m ");
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500108 n += p9_printperm(buf+n, buflen-n, st->mode);
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800109 n += scnprintf(buf+n, buflen-n, " at %d mt %d l %lld",
110 st->atime, st->mtime, (long long int) st->length);
111
112 if (extended)
113 n += scnprintf(buf+n, buflen-n, " ext '%.*s'",
114 st->extension.len, st->extension.str);
115
116 return n;
117}
118
119static int
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500120p9_dumpdata(char *buf, int buflen, u8 *data, int datalen)
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800121{
122 int i, n;
123
124 i = n = 0;
125 while (i < datalen) {
126 n += scnprintf(buf + n, buflen - n, "%02x", data[i]);
127 if (i%4 == 3)
128 n += scnprintf(buf + n, buflen - n, " ");
129 if (i%32 == 31)
130 n += scnprintf(buf + n, buflen - n, "\n");
131
132 i++;
133 }
134 n += scnprintf(buf + n, buflen - n, "\n");
135
136 return n;
137}
138
139static int
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500140p9_printdata(char *buf, int buflen, u8 *data, int datalen)
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800141{
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500142 return p9_dumpdata(buf, buflen, data, datalen < 16?datalen:16);
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800143}
144
Eric Van Hensbergenee443992008-03-05 07:08:09 -0600145/**
146 * p9_printfcall - decode and print a protocol structure into a buffer
147 * @buf: buffer to deposit decoded structure into
148 * @buflen: available space in buffer
149 * @fc: protocol rpc structure of type &p9_fcall
150 * @extended: whether or not session is operating with extended protocol
151 */
152
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800153int
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500154p9_printfcall(char *buf, int buflen, struct p9_fcall *fc, int extended)
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800155{
156 int i, ret, type, tag;
157
158 if (!fc)
159 return scnprintf(buf, buflen, "<NULL>");
160
161 type = fc->id;
162 tag = fc->tag;
163
164 ret = 0;
165 switch (type) {
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500166 case P9_TVERSION:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800167 ret += scnprintf(buf+ret, buflen-ret,
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500168 "Tversion tag %u msize %u version '%.*s'", tag,
169 fc->params.tversion.msize,
170 fc->params.tversion.version.len,
171 fc->params.tversion.version.str);
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800172 break;
173
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500174 case P9_RVERSION:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800175 ret += scnprintf(buf+ret, buflen-ret,
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500176 "Rversion tag %u msize %u version '%.*s'", tag,
177 fc->params.rversion.msize,
178 fc->params.rversion.version.len,
179 fc->params.rversion.version.str);
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800180 break;
181
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500182 case P9_TAUTH:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800183 ret += scnprintf(buf+ret, buflen-ret,
184 "Tauth tag %u afid %d uname '%.*s' aname '%.*s'", tag,
185 fc->params.tauth.afid, fc->params.tauth.uname.len,
186 fc->params.tauth.uname.str, fc->params.tauth.aname.len,
187 fc->params.tauth.aname.str);
188 break;
189
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500190 case P9_RAUTH:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800191 ret += scnprintf(buf+ret, buflen-ret, "Rauth tag %u qid ", tag);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500192 p9_printqid(buf+ret, buflen-ret, &fc->params.rauth.qid);
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800193 break;
194
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500195 case P9_TATTACH:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800196 ret += scnprintf(buf+ret, buflen-ret,
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500197 "Tattach tag %u fid %d afid %d uname '%.*s' aname '%.*s'", tag,
198 fc->params.tattach.fid, fc->params.tattach.afid,
199 fc->params.tattach.uname.len, fc->params.tattach.uname.str,
200 fc->params.tattach.aname.len, fc->params.tattach.aname.str);
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800201 break;
202
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500203 case P9_RATTACH:
204 ret += scnprintf(buf+ret, buflen-ret, "Rattach tag %u qid ",
205 tag);
206 p9_printqid(buf+ret, buflen-ret, &fc->params.rattach.qid);
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800207 break;
208
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500209 case P9_RERROR:
210 ret += scnprintf(buf+ret, buflen-ret,
211 "Rerror tag %u ename '%.*s'", tag,
212 fc->params.rerror.error.len,
213 fc->params.rerror.error.str);
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800214 if (extended)
215 ret += scnprintf(buf+ret, buflen-ret, " ecode %d\n",
216 fc->params.rerror.errno);
217 break;
218
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500219 case P9_TFLUSH:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800220 ret += scnprintf(buf+ret, buflen-ret, "Tflush tag %u oldtag %u",
221 tag, fc->params.tflush.oldtag);
222 break;
223
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500224 case P9_RFLUSH:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800225 ret += scnprintf(buf+ret, buflen-ret, "Rflush tag %u", tag);
226 break;
227
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500228 case P9_TWALK:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800229 ret += scnprintf(buf+ret, buflen-ret,
230 "Twalk tag %u fid %d newfid %d nwname %d", tag,
231 fc->params.twalk.fid, fc->params.twalk.newfid,
232 fc->params.twalk.nwname);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500233 for (i = 0; i < fc->params.twalk.nwname; i++)
234 ret += scnprintf(buf+ret, buflen-ret, " '%.*s'",
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800235 fc->params.twalk.wnames[i].len,
236 fc->params.twalk.wnames[i].str);
237 break;
238
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500239 case P9_RWALK:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800240 ret += scnprintf(buf+ret, buflen-ret, "Rwalk tag %u nwqid %d",
241 tag, fc->params.rwalk.nwqid);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500242 for (i = 0; i < fc->params.rwalk.nwqid; i++)
243 ret += p9_printqid(buf+ret, buflen-ret,
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800244 &fc->params.rwalk.wqids[i]);
245 break;
246
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500247 case P9_TOPEN:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800248 ret += scnprintf(buf+ret, buflen-ret,
249 "Topen tag %u fid %d mode %d", tag,
250 fc->params.topen.fid, fc->params.topen.mode);
251 break;
252
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500253 case P9_ROPEN:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800254 ret += scnprintf(buf+ret, buflen-ret, "Ropen tag %u", tag);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500255 ret += p9_printqid(buf+ret, buflen-ret, &fc->params.ropen.qid);
256 ret += scnprintf(buf+ret, buflen-ret, " iounit %d",
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800257 fc->params.ropen.iounit);
258 break;
259
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500260 case P9_TCREATE:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800261 ret += scnprintf(buf+ret, buflen-ret,
262 "Tcreate tag %u fid %d name '%.*s' perm ", tag,
263 fc->params.tcreate.fid, fc->params.tcreate.name.len,
264 fc->params.tcreate.name.str);
265
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500266 ret += p9_printperm(buf+ret, buflen-ret,
267 fc->params.tcreate.perm);
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800268 ret += scnprintf(buf+ret, buflen-ret, " mode %d",
269 fc->params.tcreate.mode);
270 break;
271
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500272 case P9_RCREATE:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800273 ret += scnprintf(buf+ret, buflen-ret, "Rcreate tag %u", tag);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500274 ret += p9_printqid(buf+ret, buflen-ret,
275 &fc->params.rcreate.qid);
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800276 ret += scnprintf(buf+ret, buflen-ret, " iounit %d",
277 fc->params.rcreate.iounit);
278 break;
279
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500280 case P9_TREAD:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800281 ret += scnprintf(buf+ret, buflen-ret,
282 "Tread tag %u fid %d offset %lld count %u", tag,
283 fc->params.tread.fid,
284 (long long int) fc->params.tread.offset,
285 fc->params.tread.count);
286 break;
287
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500288 case P9_RREAD:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800289 ret += scnprintf(buf+ret, buflen-ret,
290 "Rread tag %u count %u data ", tag,
291 fc->params.rread.count);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500292 ret += p9_printdata(buf+ret, buflen-ret, fc->params.rread.data,
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800293 fc->params.rread.count);
294 break;
295
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500296 case P9_TWRITE:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800297 ret += scnprintf(buf+ret, buflen-ret,
298 "Twrite tag %u fid %d offset %lld count %u data ",
299 tag, fc->params.twrite.fid,
300 (long long int) fc->params.twrite.offset,
301 fc->params.twrite.count);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500302 ret += p9_printdata(buf+ret, buflen-ret, fc->params.twrite.data,
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800303 fc->params.twrite.count);
304 break;
305
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500306 case P9_RWRITE:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800307 ret += scnprintf(buf+ret, buflen-ret, "Rwrite tag %u count %u",
308 tag, fc->params.rwrite.count);
309 break;
310
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500311 case P9_TCLUNK:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800312 ret += scnprintf(buf+ret, buflen-ret, "Tclunk tag %u fid %d",
313 tag, fc->params.tclunk.fid);
314 break;
315
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500316 case P9_RCLUNK:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800317 ret += scnprintf(buf+ret, buflen-ret, "Rclunk tag %u", tag);
318 break;
319
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500320 case P9_TREMOVE:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800321 ret += scnprintf(buf+ret, buflen-ret, "Tremove tag %u fid %d",
322 tag, fc->params.tremove.fid);
323 break;
324
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500325 case P9_RREMOVE:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800326 ret += scnprintf(buf+ret, buflen-ret, "Rremove tag %u", tag);
327 break;
328
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500329 case P9_TSTAT:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800330 ret += scnprintf(buf+ret, buflen-ret, "Tstat tag %u fid %d",
331 tag, fc->params.tstat.fid);
332 break;
333
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500334 case P9_RSTAT:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800335 ret += scnprintf(buf+ret, buflen-ret, "Rstat tag %u ", tag);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500336 ret += p9_printstat(buf+ret, buflen-ret, &fc->params.rstat.stat,
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800337 extended);
338 break;
339
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500340 case P9_TWSTAT:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800341 ret += scnprintf(buf+ret, buflen-ret, "Twstat tag %u fid %d ",
342 tag, fc->params.twstat.fid);
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500343 ret += p9_printstat(buf+ret, buflen-ret,
344 &fc->params.twstat.stat, extended);
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800345 break;
346
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500347 case P9_RWSTAT:
Latchesar Ionkov5174fda2006-03-25 03:07:25 -0800348 ret += scnprintf(buf+ret, buflen-ret, "Rwstat tag %u", tag);
349 break;
350
351 default:
352 ret += scnprintf(buf+ret, buflen-ret, "unknown type %d", type);
353 break;
354 }
355
356 return ret;
357}
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500358#else
359int
360p9_printfcall(char *buf, int buflen, struct p9_fcall *fc, int extended)
361{
362 return 0;
363}
Latchesar Ionkovbd238fb2007-07-10 17:57:28 -0500364#endif /* CONFIG_NET_9P_DEBUG */
Andrew Morton72767442008-02-06 19:25:01 -0600365EXPORT_SYMBOL(p9_printfcall);
366