2 * linux/fs/9p/fcprint.c
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/config.h>
25 #include <linux/module.h>
26 #include <linux/errno.h>
28 #include <linux/idr.h>
36 v9fs_printqid(char *buf, int buflen, struct v9fs_qid *q)
42 if (q->type & V9FS_QTDIR)
44 if (q->type & V9FS_QTAPPEND)
46 if (q->type & V9FS_QTAUTH)
48 if (q->type & V9FS_QTEXCL)
50 if (q->type & V9FS_QTTMP)
52 if (q->type & V9FS_QTSYMLINK)
56 return scnprintf(buf, buflen, "(%.16llx %x %s)", (long long int) q->path,
61 v9fs_printperm(char *buf, int buflen, int perm)
67 if (perm & V9FS_DMDIR)
69 if (perm & V9FS_DMAPPEND)
71 if (perm & V9FS_DMAUTH)
73 if (perm & V9FS_DMEXCL)
75 if (perm & V9FS_DMTMP)
77 if (perm & V9FS_DMDEVICE)
79 if (perm & V9FS_DMSOCKET)
81 if (perm & V9FS_DMNAMEDPIPE)
83 if (perm & V9FS_DMSYMLINK)
87 return scnprintf(buf, buflen, "%s%03o", b, perm&077);
91 v9fs_printstat(char *buf, int buflen, struct v9fs_stat *st, int extended)
95 n = scnprintf(buf, buflen, "'%.*s' '%.*s'", st->name.len,
96 st->name.str, st->uid.len, st->uid.str);
98 n += scnprintf(buf+n, buflen-n, "(%d)", st->n_uid);
100 n += scnprintf(buf+n, buflen-n, " '%.*s'", st->gid.len, st->gid.str);
102 n += scnprintf(buf+n, buflen-n, "(%d)", st->n_gid);
104 n += scnprintf(buf+n, buflen-n, " '%.*s'", st->muid.len, st->muid.str);
106 n += scnprintf(buf+n, buflen-n, "(%d)", st->n_muid);
108 n += scnprintf(buf+n, buflen-n, " q ");
109 n += v9fs_printqid(buf+n, buflen-n, &st->qid);
110 n += scnprintf(buf+n, buflen-n, " m ");
111 n += v9fs_printperm(buf+n, buflen-n, st->mode);
112 n += scnprintf(buf+n, buflen-n, " at %d mt %d l %lld",
113 st->atime, st->mtime, (long long int) st->length);
116 n += scnprintf(buf+n, buflen-n, " ext '%.*s'",
117 st->extension.len, st->extension.str);
123 v9fs_dumpdata(char *buf, int buflen, u8 *data, int datalen)
128 while (i < datalen) {
129 n += scnprintf(buf + n, buflen - n, "%02x", data[i]);
131 n += scnprintf(buf + n, buflen - n, " ");
133 n += scnprintf(buf + n, buflen - n, "\n");
137 n += scnprintf(buf + n, buflen - n, "\n");
143 v9fs_printdata(char *buf, int buflen, u8 *data, int datalen)
145 return v9fs_dumpdata(buf, buflen, data, datalen<16?datalen:16);
149 v9fs_printfcall(char *buf, int buflen, struct v9fs_fcall *fc, int extended)
151 int i, ret, type, tag;
154 return scnprintf(buf, buflen, "<NULL>");
162 ret += scnprintf(buf+ret, buflen-ret,
163 "Tversion tag %u msize %u version '%.*s'", tag,
164 fc->params.tversion.msize, fc->params.tversion.version.len,
165 fc->params.tversion.version.str);
169 ret += scnprintf(buf+ret, buflen-ret,
170 "Rversion tag %u msize %u version '%.*s'", tag,
171 fc->params.rversion.msize, fc->params.rversion.version.len,
172 fc->params.rversion.version.str);
176 ret += scnprintf(buf+ret, buflen-ret,
177 "Tauth tag %u afid %d uname '%.*s' aname '%.*s'", tag,
178 fc->params.tauth.afid, fc->params.tauth.uname.len,
179 fc->params.tauth.uname.str, fc->params.tauth.aname.len,
180 fc->params.tauth.aname.str);
184 ret += scnprintf(buf+ret, buflen-ret, "Rauth tag %u qid ", tag);
185 v9fs_printqid(buf+ret, buflen-ret, &fc->params.rauth.qid);
189 ret += scnprintf(buf+ret, buflen-ret,
190 "Tattach tag %u fid %d afid %d uname '%.*s' aname '%.*s'",
191 tag, fc->params.tattach.fid, fc->params.tattach.afid,
192 fc->params.tattach.uname.len, fc->params.tattach.uname.str,
193 fc->params.tattach.aname.len, fc->params.tattach.aname.str);
197 ret += scnprintf(buf+ret, buflen-ret, "Rattach tag %u qid ", tag);
198 v9fs_printqid(buf+ret, buflen-ret, &fc->params.rattach.qid);
202 ret += scnprintf(buf+ret, buflen-ret, "Rerror tag %u ename '%.*s'",
203 tag, fc->params.rerror.error.len,
204 fc->params.rerror.error.str);
206 ret += scnprintf(buf+ret, buflen-ret, " ecode %d\n",
207 fc->params.rerror.errno);
211 ret += scnprintf(buf+ret, buflen-ret, "Tflush tag %u oldtag %u",
212 tag, fc->params.tflush.oldtag);
216 ret += scnprintf(buf+ret, buflen-ret, "Rflush tag %u", tag);
220 ret += scnprintf(buf+ret, buflen-ret,
221 "Twalk tag %u fid %d newfid %d nwname %d", tag,
222 fc->params.twalk.fid, fc->params.twalk.newfid,
223 fc->params.twalk.nwname);
224 for(i = 0; i < fc->params.twalk.nwname; i++)
225 ret += scnprintf(buf+ret, buflen-ret," '%.*s'",
226 fc->params.twalk.wnames[i].len,
227 fc->params.twalk.wnames[i].str);
231 ret += scnprintf(buf+ret, buflen-ret, "Rwalk tag %u nwqid %d",
232 tag, fc->params.rwalk.nwqid);
233 for(i = 0; i < fc->params.rwalk.nwqid; i++)
234 ret += v9fs_printqid(buf+ret, buflen-ret,
235 &fc->params.rwalk.wqids[i]);
239 ret += scnprintf(buf+ret, buflen-ret,
240 "Topen tag %u fid %d mode %d", tag,
241 fc->params.topen.fid, fc->params.topen.mode);
245 ret += scnprintf(buf+ret, buflen-ret, "Ropen tag %u", tag);
246 ret += v9fs_printqid(buf+ret, buflen-ret, &fc->params.ropen.qid);
247 ret += scnprintf(buf+ret, buflen-ret," iounit %d",
248 fc->params.ropen.iounit);
252 ret += scnprintf(buf+ret, buflen-ret,
253 "Tcreate tag %u fid %d name '%.*s' perm ", tag,
254 fc->params.tcreate.fid, fc->params.tcreate.name.len,
255 fc->params.tcreate.name.str);
257 ret += v9fs_printperm(buf+ret, buflen-ret, fc->params.tcreate.perm);
258 ret += scnprintf(buf+ret, buflen-ret, " mode %d",
259 fc->params.tcreate.mode);
263 ret += scnprintf(buf+ret, buflen-ret, "Rcreate tag %u", tag);
264 ret += v9fs_printqid(buf+ret, buflen-ret, &fc->params.rcreate.qid);
265 ret += scnprintf(buf+ret, buflen-ret, " iounit %d",
266 fc->params.rcreate.iounit);
270 ret += scnprintf(buf+ret, buflen-ret,
271 "Tread tag %u fid %d offset %lld count %u", tag,
272 fc->params.tread.fid,
273 (long long int) fc->params.tread.offset,
274 fc->params.tread.count);
278 ret += scnprintf(buf+ret, buflen-ret,
279 "Rread tag %u count %u data ", tag,
280 fc->params.rread.count);
281 ret += v9fs_printdata(buf+ret, buflen-ret, fc->params.rread.data,
282 fc->params.rread.count);
286 ret += scnprintf(buf+ret, buflen-ret,
287 "Twrite tag %u fid %d offset %lld count %u data ",
288 tag, fc->params.twrite.fid,
289 (long long int) fc->params.twrite.offset,
290 fc->params.twrite.count);
291 ret += v9fs_printdata(buf+ret, buflen-ret, fc->params.twrite.data,
292 fc->params.twrite.count);
296 ret += scnprintf(buf+ret, buflen-ret, "Rwrite tag %u count %u",
297 tag, fc->params.rwrite.count);
301 ret += scnprintf(buf+ret, buflen-ret, "Tclunk tag %u fid %d",
302 tag, fc->params.tclunk.fid);
306 ret += scnprintf(buf+ret, buflen-ret, "Rclunk tag %u", tag);
310 ret += scnprintf(buf+ret, buflen-ret, "Tremove tag %u fid %d",
311 tag, fc->params.tremove.fid);
315 ret += scnprintf(buf+ret, buflen-ret, "Rremove tag %u", tag);
319 ret += scnprintf(buf+ret, buflen-ret, "Tstat tag %u fid %d",
320 tag, fc->params.tstat.fid);
324 ret += scnprintf(buf+ret, buflen-ret, "Rstat tag %u ", tag);
325 ret += v9fs_printstat(buf+ret, buflen-ret, &fc->params.rstat.stat,
330 ret += scnprintf(buf+ret, buflen-ret, "Twstat tag %u fid %d ",
331 tag, fc->params.twstat.fid);
332 ret += v9fs_printstat(buf+ret, buflen-ret, &fc->params.twstat.stat,
337 ret += scnprintf(buf+ret, buflen-ret, "Rwstat tag %u", tag);
341 ret += scnprintf(buf+ret, buflen-ret, "unknown type %d", type);