i = read(ctl, ctldata, sizeof(ctldata) - 1);
if (i <= 0)
sysfatal("%s: %r", ctlfile);
ctldata[i] = '\0';
i = tokenize(ctldata, args, nelem(args));
if(i < 7)
sysfatal("bad flash geometry");
nsects = atoi(args[5]);
sectsize = atoi(args[6]);
if(nsects < 3)
sysfatal("unreasonable value for nsects: %lud", nsects);
if(sectsize < 512)
sysfatal("unreasonable value for sectsize: %lud", sectsize);
/* allocate a buffer and read in the whole file */
n = d->length;
buf = malloc(n + sectsize);
if(buf == nil)
sysfatal("not enough room to read in file: %r");
print("reading %d bytes of %s\n", n, file);
if(readn(in, buf, n) != n)
sysfatal("error reading file: %r");
close(in);
memset(buf + n, 0, sectsize);
n = ((n+sectsize-1)/sectsize)*sectsize;
if (nsects * sectsize < n)
sysfatal("file too large (%d) for partition (%lud)", n, nsects * sectsize);