10 def print_offset(offset
):
11 if offset
== no_offset
:
12 return "NNPFS_NO_OFFSET"
15 def print_handle(handle
):
16 (a
, b
, c
, d
) = struct
.unpack(byteorder
+ "LLLL", handle
)
17 return "(%d, %d, %d, %d)" % (a
, b
, c
, d
)
19 def print_block_handle(handle
):
20 (a
, b
, c
, d
) = struct
.unpack(byteorder
+ "LLLL", handle
[0:16])
21 (offset
, ) = struct
.unpack(byteorder
+ "Q", handle
[16:24])
22 return "(%d, %d, %d, %d) @%s" % (a
, b
, c
, d
, print_offset(offset
))
25 return "\"" + s
.split("\0", 1)[0] + "\""
28 return time
.strftime("%Y-%m-%d %H:%M:%S", time
.localtime(sec
))
30 def print_valid(s
, valid
, shift
):
32 if valid
& mask
== mask
:
38 (valid
,mode
,nlink
,type,uid
,gid
,atime
,mtime
,ctime
,fileid
,size
) = struct
.unpack(byteorder
+ "LLLLLLLLLLQ", data
)
41 l1
.append(print_valid("mode %o" % mode
, valid
, 0))
42 l1
.append(print_valid("lnks %d" % nlink
, valid
, 1))
43 l1
.append(print_valid("type %d" % type, valid
, 2))
44 l1
.append(print_valid("uid %d" % uid
, valid
, 3))
45 l1
.append(print_valid("gid %d" % gid
, valid
, 4))
46 l1
.append(print_valid("fid %d" % fileid
, valid
, 8))
47 l1
.append(print_valid("size %d" % size
, valid
, 9))
49 l2
.append(print_valid("atime %s" % print_time(atime
), valid
, 5))
50 l2
.append(print_valid("mtime %s" % print_time(mtime
), valid
, 6))
51 l2
.append(print_valid("ctime %s" % print_time(ctime
), valid
, 7))
53 return (" ".join(l1
), " ".join(l2
))
55 return (" ".join(l2
), "")
57 def print_right(right
):
59 if (right
& 0x1) == 0x1:
61 if (right
& 0x2) == 0x2:
63 if (right
& 0x4) == 0x4:
69 def print_rights(iddata
, rightsdata
):
70 ids
= struct
.unpack(byteorder
+ "8L", iddata
)
71 rights
= struct
.unpack(byteorder
+ "8H", rightsdata
)
73 for id, right
in zip(ids
, rights
):
75 ret
.append("%d:%s" % (id, print_right(right
)))
78 def bitfield_print(field
, template
):
80 for (bit
, t
) in template
:
81 if (field
& bit
) == bit
:
85 def print_tokens(tokens
):
98 return "|".join(bitfield_print(tokens
, template
))
100 def print_node(data
):
101 handle
= print_handle(data
[0:16])
102 (tokens
,pad1
) = struct
.unpack(byteorder
+ "LL", data
[16:24])
103 (attr1
, attr2
) = print_attr(data
[24:72])
104 rights
= print_rights(data
[72:104], data
[104:120])
105 (anonrights
,) = struct
.unpack(byteorder
+ "H", data
[120:122])
106 anonrights_str
= print_right(anonrights
)
107 return ("handle %s tokens %s anonrights %s rights %s" % (handle
, print_tokens(tokens
), anonrights_str
, rights
), attr1
, attr2
)
109 def process_wakeup(data
):
110 (seqno
, error
, len) = struct
.unpack(byteorder
+ "LLL", data
[0:12])
111 print "wakeup seqno", seqno
, "error", error
113 def process_getroot(data
):
114 (uid
, pag
) = struct
.unpack(byteorder
+ "LL", data
[0:8])
115 print "getroot uid", uid
, "pag", pag
117 def process_getnode(data
):
118 (uid
, pag
) = struct
.unpack(byteorder
+ "LL", data
[0:8])
119 handle
= print_handle(data
[8:24])
121 print "getnode uid", uid
, "pag", pag
, "parenthandle", handle
, "name", print_asciz(name
)
123 def process_inactivenode(data
):
124 handle
= print_handle(data
[0:16])
125 (flag
,) = struct
.unpack(byteorder
+ "L", data
[16:20])
128 flagtexts
.append("norefs")
130 flagtexts
.append("delete")
131 print "inactivenode handle", handle
, "flags", "|".join(flagtexts
)
133 def process_open(data
):
134 (uid
, pag
) = struct
.unpack(byteorder
+ "LL", data
[0:8])
135 handle
= print_handle(data
[8:24])
136 (tokens
, ) = struct
.unpack(byteorder
+ "L", data
[24:28])
137 print "open uid", uid
, "pag", pag
, "handle", handle
, "tokens", print_tokens(tokens
)
139 def process_version(data
):
142 def process_installroot(data
):
143 (line1
, line2
, line3
) = print_node(data
[0:128])
144 print "installroot " + line1
148 def process_installnode(data
):
149 handle
= print_handle(data
[0:16])
150 name
= print_asciz(data
[16:272])
151 (line1
, line2
, line3
) = print_node(data
[272:400])
152 print "installnode parenthandle %s name %s" % (handle
, name
)
157 def process_getdata(data
):
158 (uid
, pag
) = struct
.unpack(byteorder
+ "LL", data
[0:8])
159 handle
= print_handle(data
[8:24])
160 (tokens
, pad1
) = struct
.unpack(byteorder
+ "LL", data
[24:32])
161 (offset
, len) = struct
.unpack(byteorder
+ "QQ", data
[32:48])
162 print "getdata uid", uid
, "pag", pag
, "handle", handle
, "tokens", print_tokens(tokens
)
163 print "offset", offset
, "len", len
165 def process_installdata(data
):
166 # don't print cache handle
167 (line1
, line2
, line3
) = print_node(data
[0:128])
168 (flag
, id) = struct
.unpack(byteorder
+ "LL", data
[128:136])
169 (offset
,) = struct
.unpack(byteorder
+ "Q", data
[136:144])
170 off
= print_offset(offset
)
172 (0x0001, "INVALID_DNLC"),
174 (0x0004, "HANDLE_VALID")
176 print "installdata " + line1
179 print " flag", "|".join(bitfield_print(flag
, template
)), "offset", off
, "id", id
181 def process_deletenode(data
):
182 handle
= print_handle(data
[0:16])
183 print "deletenode handle", handle
185 def process_putdata(data
):
186 handle
= print_handle(data
[0:16])
187 (attr1
, attr2
) = print_attr(data
[16:64])
188 (uid
, pag
) = struct
.unpack(byteorder
+ "LL", data
[64:72])
189 (flag
, pad1
) = struct
.unpack(byteorder
+ "LL", data
[72:80])
190 (offset
, len) = struct
.unpack(byteorder
+ "QQ", data
[80:96])
191 print "putdata handle", handle
, "offset", offset
, "len", len
192 print "uid", uid
, "pag", pag
, "flag", flag
196 def process_create(data
):
197 handle
= print_handle(data
[0:16])
198 name
= print_asciz(data
[16:272])
199 (attr1
, attr2
) = print_attr(data
[272:320])
200 (mode
, pad1
) = struct
.unpack(byteorder
+ "LL", data
[320:328])
201 (uid
, pag
) = struct
.unpack(byteorder
+ "LL", data
[328:336])
202 print "create parent", handle
, "mode", mode
, "uid", uid
, "pag", pag
, "name", name
206 def process_putattr(data
):
207 handle
= print_handle(data
[0:16])
208 (attr1
, attr2
) = print_attr(data
[16:64])
209 (uid
, pag
) = struct
.unpack(byteorder
+ "LL", data
[64:72])
210 print "putattr handle", handle
, "uid", uid
, "pag", pag
214 def process_installattr(data
):
215 (line1
, line2
, line3
) = print_node(data
[0:128])
216 (flag
, pad1
) = struct
.unpack(byteorder
+ "LL", data
[128:136])
217 print "installattr " + line1
222 def process_getattr(data
):
223 (uid
, pag
) = struct
.unpack(byteorder
+ "LL", data
[0:8])
224 handle
= print_handle(data
[8:24])
225 print "getattr handle", handle
, "uid", uid
, "pag", pag
227 def process_invalidnode(data
):
228 handle
= print_handle(data
[0:16])
229 print "invalidnode handle", handle
231 def process_mkdir(data
):
232 handle
= print_handle(data
[0:16])
233 name
= print_asciz(data
[16:272])
234 (attr1
, attr2
) = print_attr(data
[272:320])
235 (uid
, pag
) = struct
.unpack(byteorder
+ "LL", data
[320:328])
236 print "mkdir parent", handle
, "uid", uid
, "pag", pag
, "name", name
240 def process_link(data
):
241 parenthandle
= print_handle(data
[0:16])
242 name
= print_asciz(data
[16:272])
243 fromhandle
= print_handle(data
[272:288])
244 (uid
, pag
) = struct
.unpack(byteorder
+ "LL", data
[288:296])
245 print "link parent", parenthandle
, "fromhandle", fromhandle
, "name", name
247 def process_symlink(data
):
248 parenthandle
= print_handle(data
[0:16])
249 name
= print_asciz(data
[16:272])
250 content
= print_asciz(data
[272:2320])
251 (attr1
, attr2
) = print_attr(data
[2320:2368])
252 (uid
, pag
) = struct
.unpack(byteorder
+ "LL", data
[2368:2376])
253 print "symlink parent", parenthandle
, "uid", uid
, "pag", pag
254 print " " + name
+ "->" + content
258 def process_remove(data
):
259 parenthandle
= print_handle(data
[0:16])
260 name
= print_asciz(data
[16:272])
261 (uid
, pag
) = struct
.unpack(byteorder
+ "LL", data
[272:280])
262 print "remove parent", parenthandle
, "uid", uid
, "pag", pag
, "name", name
264 def process_rmdir(data
):
265 parenthandle
= print_handle(data
[0:16])
266 name
= print_asciz(data
[16:272])
267 (uid
, pag
) = struct
.unpack(byteorder
+ "LL", data
[272:280])
268 print "rmdir parent", parenthandle
, "uid", uid
, "pag", pag
, "name", name
270 def process_rename(data
):
271 oldparenthandle
= print_handle(data
[0:16])
272 oldname
= print_asciz(data
[16:272])
273 newparenthandle
= print_handle(data
[272:288])
274 newname
= print_asciz(data
[288:544])
275 (uid
, pag
) = struct
.unpack(byteorder
+ "LL", data
[544:552])
276 print "rename oldparent", oldparenthandle
, "oldname", oldname
277 print " newparent", newparenthandle
, "newname", newname
278 print " uid", uid
, "pag", pag
280 def ioctl_decode(opcode
):
282 type = (opcode
>> 8) & 0xff
283 size
= (opcode
>> 16) & 0x3fff
284 dir = (opcode
>> 30) & 0x3
285 if (type > 64 and type < 91):
286 typeprint
= "%d(%s)" % (type, chr(type))
288 typeprint
= "%d" % type
289 return (nr
, type, typeprint
, size
, dir)
291 def pioctl_settok(data
):
294 def pioctl_flush(data
):
297 def pioctl_afs_delete_mt_pt(data
):
298 return "afs_delete_mt_pt"
300 def pioctl_getfid(data
):
303 def pioctl_file_cell_name(data
):
304 return "file_cell_name"
306 def print_pioctl(opcode
, data
):
308 return {(3, 86, 12, 1): pioctl_settok
,
309 (6, 86, 12, 1): pioctl_flush
,
310 (22, 86, 12, 1): pioctl_getfid
,
311 (30, 86, 12, 1): pioctl_file_cell_name
,
312 (28, 86, 12, 1): pioctl_afs_delete_mt_pt
} [opcode
] (data
)
314 return " Unknown opcode" + str(opcode
)
316 def process_pioctl(data
):
317 (opcode
, pad1
) = struct
.unpack(byteorder
+ "LL", data
[0:8])
318 (uid
, pag
) = struct
.unpack(byteorder
+ "LL", data
[8:16])
319 (insize
, outsize
) = struct
.unpack(byteorder
+ "LL", data
[16:24])
321 handle
= print_handle(data
[2072:2088])
322 print "pioctl opcode %08x uid %d pag %d insize %d outsize %d" % (opcode
, uid
, pag
, insize
, outsize
)
323 print " handle", handle
325 # this is linux specific now
326 (nr
, type, typeprint
, size
, dir) = ioctl_decode(opcode
)
327 print " type", typeprint
, "nr", nr
, "size", size
, "dir", dir
328 print " " + print_pioctl((nr
, type, size
, dir), msg
)
330 for i
in msg
[0:insize
]:
331 s
.append("%02x" % ord(i
))
333 print " " + " ".join(s
[0:8])
335 print " " + " ".join(s
)
337 def process_updatefid(data
):
338 oldhandle
= print_handle(data
[0:16])
339 newhandle
= print_handle(data
[16:32])
340 print "updatefid oldhandle %s newhandle %s" % (oldhandle
, newhandle
)
342 def process_advlock(data
):
345 def process_gc(data
):
346 (len, pad
) = struct
.unpack(byteorder
+ "LL", data
[0:8])
351 print print_block_handle(data
[offset
:offset
+24])
355 def process_appenddata(data
):
356 handle
= print_block_handle(data
[0:24])
357 print "appenddata", handle
359 def process_deletedata(data
):
360 handle
= print_block_handle(data
[0:24])
361 print "deletedata", handle
363 def process_accesses(data
):
366 def process_installquota(data
):
367 (appendquota
,) = struct
.unpack(byteorder
+ "Q", data
[0:8])
368 print "installquota", "append", appendquota
370 def process_message(size
, opcode
, seqno
, data
):
371 sys
.stdout
.write (" %4d:" % seqno
)
373 { 0: process_version
,
376 3: process_installroot
,
378 5: process_installnode
,
380 7: process_installattr
,
382 9: process_installdata
,
383 10: process_inactivenode
,
384 11: process_invalidnode
,
396 23: process_updatefid
,
399 26: process_deletenode
,
400 27: process_appenddata
,
401 28: process_deletedata
,
402 29: process_accesses
,
403 30: process_installquota
} [opcode
] (data
)
405 print " Unknown opcode", opcode
408 data
= sys
.stdin
.read(16)
411 (type, sec
, usec
, length
) = struct
.unpack('!LLLL', data
)
412 if type == 0x00000001:
415 elif type == 0x00000002:
418 elif type == 0x01000000:
421 elif type == 0x02000000:
427 print time
.strftime("%Y-%m-%d %H:%M:%S", time
.localtime(sec
)) + ".%06d" % usec
, typetext
, "len", length
428 messages
= sys
.stdin
.read(length
)
429 if len(messages
) != length
:
432 header
= messages
[0:16]
433 (size
, opcode
, seqno
, pad1
) = struct
.unpack(byteorder
+ "LLLL", header
)
434 message
= messages
[0:size
]
435 process_message(size
, opcode
, seqno
, message
[16:])
437 messages
= messages
[size
:]