aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/fossil/epoch.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/fossil/epoch.c')
-rw-r--r--src/cmd/fossil/epoch.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/cmd/fossil/epoch.c b/src/cmd/fossil/epoch.c
new file mode 100644
index 00000000..6aa73bbf
--- /dev/null
+++ b/src/cmd/fossil/epoch.c
@@ -0,0 +1,51 @@
+#include "stdinc.h"
+#include "dat.h"
+#include "fns.h"
+
+uchar buf[65536];
+
+void
+usage(void)
+{
+ fprint(2, "usage: fossil/epoch fs [new-low-epoch]\n");
+ exits("usage");
+}
+
+void
+main(int argc, char **argv)
+{
+ int fd;
+ Header h;
+ Super s;
+
+ ARGBEGIN{
+ default:
+ usage();
+ }ARGEND
+
+ if(argc == 0 || argc > 2)
+ usage();
+
+ if((fd = open(argv[0], argc==2 ? ORDWR : OREAD)) < 0)
+ sysfatal("open %s: %r", argv[0]);
+
+ if(pread(fd, buf, HeaderSize, HeaderOffset) != HeaderSize)
+ sysfatal("reading header: %r");
+ if(!headerUnpack(&h, buf))
+ sysfatal("unpacking header: %r");
+
+ if(pread(fd, buf, h.blockSize, (vlong)h.super*h.blockSize) != h.blockSize)
+ sysfatal("reading super block: %r");
+
+ if(!superUnpack(&s, buf))
+ sysfatal("unpacking super block: %r");
+
+ print("epoch %d\n", s.epochLow);
+ if(argc == 2){
+ s.epochLow = strtoul(argv[1], 0, 0);
+ superPack(&s, buf);
+ if(pwrite(fd, buf, h.blockSize, (vlong)h.super*h.blockSize) != h.blockSize)
+ sysfatal("writing super block: %r");
+ }
+ exits(0);
+}