summaryrefslogtreecommitdiff
path: root/sys/src/cmd/fossil/last.c
diff options
context:
space:
mode:
authorTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
committerTaru Karttunen <taruti@taruti.net>2011-03-30 15:46:40 +0300
commite5888a1ffdae813d7575f5fb02275c6bb07e5199 (patch)
treed8d51eac403f07814b9e936eed0c9a79195e2450 /sys/src/cmd/fossil/last.c
Import sources from 2011-03-30 iso image
Diffstat (limited to 'sys/src/cmd/fossil/last.c')
-rwxr-xr-xsys/src/cmd/fossil/last.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/sys/src/cmd/fossil/last.c b/sys/src/cmd/fossil/last.c
new file mode 100755
index 000000000..21d80811a
--- /dev/null
+++ b/sys/src/cmd/fossil/last.c
@@ -0,0 +1,40 @@
+#include <u.h>
+#include <libc.h>
+
+void
+usage(void)
+{
+ fprint(2, "usage: fossil/last disk\n");
+ exits("usage");
+}
+
+void
+main(int argc, char **argv)
+{
+ int fd, bs, addr;
+ char buf[20];
+
+ ARGBEGIN{
+ default:
+ usage();
+ }ARGEND
+
+ if(argc != 1)
+ usage();
+
+ if((fd = open(argv[0], OREAD)) < 0)
+ sysfatal("open %s: %r", argv[0]);
+
+ werrstr("end of file");
+ if(seek(fd, 131072, 0) < 0 || readn(fd, buf, 20) != 20)
+ sysfatal("error reading %s: %r", argv[0]);
+ fmtinstall('H', encodefmt);
+ if(memcmp(buf, "\x37\x76\xAE\x89", 4) != 0)
+ sysfatal("bad magic %.4H != 3776AE89", buf);
+ bs = buf[7]|(buf[6]<<8);
+ addr = (buf[8]<<24)|(buf[9]<<16)|(buf[10]<<8)|buf[11];
+ if(seek(fd, (vlong)bs*addr+34, 0) < 0 || readn(fd, buf, 20) != 20)
+ sysfatal("error reading %s: %r", argv[0]);
+ print("vac:%.20lH\n", buf);
+ exits(0);
+}