last.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. #include <u.h>
  10. #include <libc.h>
  11. void
  12. usage(void)
  13. {
  14. fprint(2, "usage: fossil/last disk\n");
  15. exits("usage");
  16. }
  17. void
  18. main(int argc, char **argv)
  19. {
  20. int fd, bs, addr;
  21. char buf[20];
  22. ARGBEGIN{
  23. default:
  24. usage();
  25. }ARGEND
  26. if(argc != 1)
  27. usage();
  28. if((fd = open(argv[0], OREAD)) < 0)
  29. sysfatal("open %s: %r", argv[0]);
  30. werrstr("end of file");
  31. if(seek(fd, 131072, 0) < 0 || readn(fd, buf, 20) != 20)
  32. sysfatal("error reading %s: %r", argv[0]);
  33. fmtinstall('H', encodefmt);
  34. if(memcmp(buf, "\x37\x76\xAE\x89", 4) != 0)
  35. sysfatal("bad magic %.4H != 3776AE89", buf);
  36. bs = buf[7]|(buf[6]<<8);
  37. addr = (buf[8]<<24)|(buf[9]<<16)|(buf[10]<<8)|buf[11];
  38. if(seek(fd, (int64_t)bs*addr+34, 0) < 0 || readn(fd, buf, 20) != 20)
  39. sysfatal("error reading %s: %r", argv[0]);
  40. print("vac:%.20lH\n", buf);
  41. exits(0);
  42. }