#include #include #include #include #include #include <9p.h> #include "flashfs.h" static void usage(void) { fprint(2, "usage: %s -n nsect -z sectsize -f file\n", prog); exits("usage"); } static ulong argval(char *arg) { long v; char *extra; if(arg == nil) usage(); v = strtol(arg, &extra, 0); if(*extra || v <= 0) usage(); return v; } void main(int argc, char **argv) { int i; int m, n; char *file; uchar hdr[MAXHDR]; file = "/dev/flash/fs"; ARGBEGIN { case 'n': nsects = argval(ARGF()); break; case 'z': sectsize = argval(ARGF()); break; case 'f': file = ARGF(); break; default: usage(); } ARGEND prog = argv0; initdata(file, 1); print("%lud sectors * %lud bytes/sec = %lud bytes\n", nsects, sectsize, nsects*sectsize); sectbuff = emalloc9p(sectsize); memmove(hdr, magic, MAGSIZE); m = putc3(&hdr[MAGSIZE], 0); n = putc3(&hdr[MAGSIZE + m], 0); print("clearing sector 0"); clearsect(0); writedata(0, 0, hdr, MAGSIZE + m + n, 0); for(i = 1; i < nsects - 1; i++){ print("\b\b%2.2d", i); clearsect(i); } print("\n"); m = putc3(&hdr[MAGSIZE], 1); n = putc3(&hdr[MAGSIZE + m], 0); clearsect(nsects - 1); writedata(0, nsects - 1, hdr, MAGSIZE + m + n, 0); }