6 * Copyright (C) 2005 by Latchesar Ionkov <lucho@ionkov.net>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2
10 * as published by the Free Software Foundation.
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.
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
24 #include <linux/module.h>
25 #include <linux/errno.h>
27 #include <linux/idr.h>
28 #include <net/9p/9p.h>
30 #ifdef CONFIG_NET_9P_DEBUG
33 p9_printqid(char *buf, int buflen, struct p9_qid *q)
39 if (q->type & P9_QTDIR)
41 if (q->type & P9_QTAPPEND)
43 if (q->type & P9_QTAUTH)
45 if (q->type & P9_QTEXCL)
47 if (q->type & P9_QTTMP)
49 if (q->type & P9_QTSYMLINK)
53 return scnprintf(buf, buflen, "(%.16llx %x %s)",
54 (long long int) q->path, q->version, b);
58 p9_printperm(char *buf, int buflen, int perm)
66 if (perm & P9_DMAPPEND)
74 if (perm & P9_DMDEVICE)
76 if (perm & P9_DMSOCKET)
78 if (perm & P9_DMNAMEDPIPE)
80 if (perm & P9_DMSYMLINK)
84 return scnprintf(buf, buflen, "%s%03o", b, perm&077);
88 p9_printstat(char *buf, int buflen, struct p9_stat *st, int extended)
92 n = scnprintf(buf, buflen, "'%.*s' '%.*s'", st->name.len,
93 st->name.str, st->uid.len, st->uid.str);
95 n += scnprintf(buf+n, buflen-n, "(%d)", st->n_uid);
97 n += scnprintf(buf+n, buflen-n, " '%.*s'", st->gid.len, st->gid.str);
99 n += scnprintf(buf+n, buflen-n, "(%d)", st->n_gid);
101 n += scnprintf(buf+n, buflen-n, " '%.*s'", st->muid.len, st->muid.str);
103 n += scnprintf(buf+n, buflen-n, "(%d)", st->n_muid);
105 n += scnprintf(buf+n, buflen-n, " q ");
106 n += p9_printqid(buf+n, buflen-n, &st->qid);
107 n += scnprintf(buf+n, buflen-n, " m ");
108 n += p9_printperm(buf+n, buflen-n, st->mode);
109 n += scnprintf(buf+n, buflen-n, " at %d mt %d l %lld",
110 st->atime, st->mtime, (long long int) st->length);
113 n += scnprintf(buf+n, buflen-n, " ext '%.*s'",
114 st->extension.len, st->extension.str);
120 p9_dumpdata(char *buf, int buflen, u8 *data, int datalen)
125 while (i < datalen) {
126 n += scnprintf(buf + n, buflen - n, "%02x", data[i]);
128 n += scnprintf(buf + n, buflen - n, " ");
130 n += scnprintf(buf + n, buflen - n, "\n");
134 n += scnprintf(buf + n, buflen - n, "\n");
140 p9_printdata(char *buf, int buflen, u8 *data, int datalen)
142 return p9_dumpdata(buf, buflen, data, datalen < 16?datalen:16);
146 p9_printfcall(char *buf, int buflen, struct p9_fcall *fc, int extended)
148 int i, ret, type, tag;
151 return scnprintf(buf, buflen, "<NULL>");
159 ret += scnprintf(buf+ret, buflen-ret,
160 "Tversion tag %u msize %u version '%.*s'", tag,
161 fc->params.tversion.msize,
162 fc->params.tversion.version.len,
163 fc->params.tversion.version.str);
167 ret += scnprintf(buf+ret, buflen-ret,
168 "Rversion tag %u msize %u version '%.*s'", tag,
169 fc->params.rversion.msize,
170 fc->params.rversion.version.len,
171 fc->params.rversion.version.str);
175 ret += scnprintf(buf+ret, buflen-ret,
176 "Tauth tag %u afid %d uname '%.*s' aname '%.*s'", tag,
177 fc->params.tauth.afid, fc->params.tauth.uname.len,
178 fc->params.tauth.uname.str, fc->params.tauth.aname.len,
179 fc->params.tauth.aname.str);
183 ret += scnprintf(buf+ret, buflen-ret, "Rauth tag %u qid ", tag);
184 p9_printqid(buf+ret, buflen-ret, &fc->params.rauth.qid);
188 ret += scnprintf(buf+ret, buflen-ret,
189 "Tattach tag %u fid %d afid %d uname '%.*s' aname '%.*s'", tag,
190 fc->params.tattach.fid, fc->params.tattach.afid,
191 fc->params.tattach.uname.len, fc->params.tattach.uname.str,
192 fc->params.tattach.aname.len, fc->params.tattach.aname.str);
196 ret += scnprintf(buf+ret, buflen-ret, "Rattach tag %u qid ",
198 p9_printqid(buf+ret, buflen-ret, &fc->params.rattach.qid);
202 ret += scnprintf(buf+ret, buflen-ret,
203 "Rerror tag %u ename '%.*s'", tag,
204 fc->params.rerror.error.len,
205 fc->params.rerror.error.str);
207 ret += scnprintf(buf+ret, buflen-ret, " ecode %d\n",
208 fc->params.rerror.errno);
212 ret += scnprintf(buf+ret, buflen-ret, "Tflush tag %u oldtag %u",
213 tag, fc->params.tflush.oldtag);
217 ret += scnprintf(buf+ret, buflen-ret, "Rflush tag %u", tag);
221 ret += scnprintf(buf+ret, buflen-ret,
222 "Twalk tag %u fid %d newfid %d nwname %d", tag,
223 fc->params.twalk.fid, fc->params.twalk.newfid,
224 fc->params.twalk.nwname);
225 for (i = 0; i < fc->params.twalk.nwname; i++)
226 ret += scnprintf(buf+ret, buflen-ret, " '%.*s'",
227 fc->params.twalk.wnames[i].len,
228 fc->params.twalk.wnames[i].str);
232 ret += scnprintf(buf+ret, buflen-ret, "Rwalk tag %u nwqid %d",
233 tag, fc->params.rwalk.nwqid);
234 for (i = 0; i < fc->params.rwalk.nwqid; i++)
235 ret += p9_printqid(buf+ret, buflen-ret,
236 &fc->params.rwalk.wqids[i]);
240 ret += scnprintf(buf+ret, buflen-ret,
241 "Topen tag %u fid %d mode %d", tag,
242 fc->params.topen.fid, fc->params.topen.mode);
246 ret += scnprintf(buf+ret, buflen-ret, "Ropen tag %u", tag);
247 ret += p9_printqid(buf+ret, buflen-ret, &fc->params.ropen.qid);
248 ret += scnprintf(buf+ret, buflen-ret, " iounit %d",
249 fc->params.ropen.iounit);
253 ret += scnprintf(buf+ret, buflen-ret,
254 "Tcreate tag %u fid %d name '%.*s' perm ", tag,
255 fc->params.tcreate.fid, fc->params.tcreate.name.len,
256 fc->params.tcreate.name.str);
258 ret += p9_printperm(buf+ret, buflen-ret,
259 fc->params.tcreate.perm);
260 ret += scnprintf(buf+ret, buflen-ret, " mode %d",
261 fc->params.tcreate.mode);
265 ret += scnprintf(buf+ret, buflen-ret, "Rcreate tag %u", tag);
266 ret += p9_printqid(buf+ret, buflen-ret,
267 &fc->params.rcreate.qid);
268 ret += scnprintf(buf+ret, buflen-ret, " iounit %d",
269 fc->params.rcreate.iounit);
273 ret += scnprintf(buf+ret, buflen-ret,
274 "Tread tag %u fid %d offset %lld count %u", tag,
275 fc->params.tread.fid,
276 (long long int) fc->params.tread.offset,
277 fc->params.tread.count);
281 ret += scnprintf(buf+ret, buflen-ret,
282 "Rread tag %u count %u data ", tag,
283 fc->params.rread.count);
284 ret += p9_printdata(buf+ret, buflen-ret, fc->params.rread.data,
285 fc->params.rread.count);
289 ret += scnprintf(buf+ret, buflen-ret,
290 "Twrite tag %u fid %d offset %lld count %u data ",
291 tag, fc->params.twrite.fid,
292 (long long int) fc->params.twrite.offset,
293 fc->params.twrite.count);
294 ret += p9_printdata(buf+ret, buflen-ret, fc->params.twrite.data,
295 fc->params.twrite.count);
299 ret += scnprintf(buf+ret, buflen-ret, "Rwrite tag %u count %u",
300 tag, fc->params.rwrite.count);
304 ret += scnprintf(buf+ret, buflen-ret, "Tclunk tag %u fid %d",
305 tag, fc->params.tclunk.fid);
309 ret += scnprintf(buf+ret, buflen-ret, "Rclunk tag %u", tag);
313 ret += scnprintf(buf+ret, buflen-ret, "Tremove tag %u fid %d",
314 tag, fc->params.tremove.fid);
318 ret += scnprintf(buf+ret, buflen-ret, "Rremove tag %u", tag);
322 ret += scnprintf(buf+ret, buflen-ret, "Tstat tag %u fid %d",
323 tag, fc->params.tstat.fid);
327 ret += scnprintf(buf+ret, buflen-ret, "Rstat tag %u ", tag);
328 ret += p9_printstat(buf+ret, buflen-ret, &fc->params.rstat.stat,
333 ret += scnprintf(buf+ret, buflen-ret, "Twstat tag %u fid %d ",
334 tag, fc->params.twstat.fid);
335 ret += p9_printstat(buf+ret, buflen-ret,
336 &fc->params.twstat.stat, extended);
340 ret += scnprintf(buf+ret, buflen-ret, "Rwstat tag %u", tag);
344 ret += scnprintf(buf+ret, buflen-ret, "unknown type %d", type);
353 p9_printfcall(char *buf, int buflen, struct p9_fcall *fc, int extended)
357 EXPORT_SYMBOL(p9_printfcall);
358 #endif /* CONFIG_NET_9P_DEBUG */