|
version 1.3, 2014/02/05 22:00:29
|
version 1.4, 2014/02/05 22:53:12
|
|
Line 48 SUCH DAMAGE.
|
Line 48 SUCH DAMAGE.
|
| |
|
| char imgName[PATH_MAX], imgFile[PATH_MAX]; |
char imgName[PATH_MAX], imgFile[PATH_MAX]; |
| off_t imgSize, iSize; |
off_t imgSize, iSize; |
| int Verbose; | int Verbose, bufSize = IMGBUF_SIZE; |
| extern char compiled[], compiledby[], compilehost[]; |
extern char compiled[], compiledby[], compilehost[]; |
| |
|
| static void |
static void |
|
Line 59 Usage()
|
Line 59 Usage()
|
| "=== %s === %s@%s ===\n\n" |
"=== %s === %s@%s ===\n\n" |
| " Syntax: imgupd [options] [image_file]\n\n" |
" Syntax: imgupd [options] [image_file]\n\n" |
| "\t-v\t\tVerbose ...\n" |
"\t-v\t\tVerbose ...\n" |
| |
"\t-R\t\tReboot system after complete\n" |
| |
"\t-p\t\tPipe suitable transfer on little chunks\n" |
| "\t-g\t\tGet image from Storage\n" |
"\t-g\t\tGet image from Storage\n" |
| "\t-t\t\tTruncate Storage file name\n" |
"\t-t\t\tTruncate Storage file name\n" |
| "\t-s <size>\tStorage size (required for stdin)\n" |
"\t-s <size>\tStorage size (required for stdin)\n" |
|
Line 70 static int
|
Line 72 static int
|
| EmptyStore(int img) |
EmptyStore(int img) |
| { |
{ |
| register int i; |
register int i; |
| u_char buf[IMGBUF_SIZE]; | u_char buf[bufSize]; |
| ssize_t wlen; |
ssize_t wlen; |
| |
|
| VERB(1) printf("Erase store %s\n", imgName); |
VERB(1) printf("Erase store %s\n", imgName); |
|
Line 80 EmptyStore(int img)
|
Line 82 EmptyStore(int img)
|
| ESYSERR(0); |
ESYSERR(0); |
| return -1; |
return -1; |
| } else |
} else |
| imgSize += E_ALIGN(iSize, IMGBUF_SIZE); | imgSize += E_ALIGN(iSize, bufSize); |
| |
|
| memset(buf, 0, sizeof buf); |
memset(buf, 0, sizeof buf); |
| for (i = howmany(iSize, IMGBUF_SIZE); i < howmany(imgSize, IMGBUF_SIZE); i++) | for (i = howmany(iSize, bufSize); i < howmany(imgSize, bufSize); i++) |
| if ((wlen = write(img, buf, sizeof buf)) == -1 || |
if ((wlen = write(img, buf, sizeof buf)) == -1 || |
| wlen != sizeof buf) { |
wlen != sizeof buf) { |
| EERROR(EIO, "Error at chunk %d init %d bytes, should be %u\n", |
EERROR(EIO, "Error at chunk %d init %d bytes, should be %u\n", |
|
Line 100 static int
|
Line 102 static int
|
| FillStore(int img, int fd) |
FillStore(int img, int fd) |
| { |
{ |
| register int i, j; |
register int i, j; |
| u_char buf[IMGBUF_SIZE]; | u_char buf[bufSize]; |
| ssize_t rlen, wlen; |
ssize_t rlen, wlen; |
| |
|
| VERB(1) printf("Fill store %s from image file %s\n", imgName, imgFile); |
VERB(1) printf("Fill store %s from image file %s\n", imgName, imgFile); |
| |
|
| for (j = 0, i = howmany(iSize, IMGBUF_SIZE); i < howmany(imgSize, IMGBUF_SIZE); | for (j = 0, i = howmany(iSize, bufSize); i < howmany(imgSize, bufSize); |
| i++, j++) { |
i++, j++) { |
| memset(buf, 0, sizeof buf); |
memset(buf, 0, sizeof buf); |
| rlen = read(fd, buf, sizeof buf); |
rlen = read(fd, buf, sizeof buf); |
|
Line 134 FillStore(int img, int fd)
|
Line 136 FillStore(int img, int fd)
|
| int |
int |
| main(int argc, char **argv) |
main(int argc, char **argv) |
| { |
{ |
| char ch, m = 0; | char ch, m = 0, R = 0; |
| int fd, img, tr = 0; |
int fd, img, tr = 0; |
| |
|
| while ((ch = getopt(argc, argv, "hvgts:f:")) != -1) | while ((ch = getopt(argc, argv, "hvRpgts:f:")) != -1) |
| switch (ch) { |
switch (ch) { |
| case 'f': |
case 'f': |
| strlcpy(imgName, optarg, sizeof imgName); |
strlcpy(imgName, optarg, sizeof imgName); |
|
Line 155 main(int argc, char **argv)
|
Line 157 main(int argc, char **argv)
|
| case 'g': |
case 'g': |
| m = 1; |
m = 1; |
| break; |
break; |
| |
case 'p': |
| |
bufSize = IMGBUF_SIZE2; |
| |
break; |
| |
case 'R': |
| |
R = 1; |
| |
break; |
| case 'v': |
case 'v': |
| Verbose++; |
Verbose++; |
| break; |
break; |
|
Line 177 main(int argc, char **argv)
|
Line 185 main(int argc, char **argv)
|
| } else |
} else |
| iSize = lseek(fd, 0, SEEK_END); |
iSize = lseek(fd, 0, SEEK_END); |
| if (!imgSize) |
if (!imgSize) |
| imgSize = E_ALIGN(iSize, IMGBUF_SIZE); | imgSize = E_ALIGN(iSize, bufSize); |
| if (iSize == -1 || iSize > imgSize) { |
if (iSize == -1 || iSize > imgSize) { |
| close(fd); |
close(fd); |
| EERROR(ENOSPC, "Error:: file size %llu is " |
EERROR(ENOSPC, "Error:: file size %llu is " |
|
Line 230 main(int argc, char **argv)
|
Line 238 main(int argc, char **argv)
|
| } else |
} else |
| iSize = lseek(img, 0, SEEK_END); |
iSize = lseek(img, 0, SEEK_END); |
| if (!imgSize) |
if (!imgSize) |
| imgSize = E_ALIGN(iSize, IMGBUF_SIZE); | imgSize = E_ALIGN(iSize, bufSize); |
| if (iSize == -1 || iSize > imgSize) { |
if (iSize == -1 || iSize > imgSize) { |
| if (fd > 2) |
if (fd > 2) |
| close(fd); |
close(fd); |
|
Line 274 main(int argc, char **argv)
|
Line 282 main(int argc, char **argv)
|
| close(img); |
close(img); |
| if (fd > 2) |
if (fd > 2) |
| close(fd); |
close(fd); |
| |
|
| |
if (R) |
| |
reboot(RB_AUTOBOOT); |
| return 0; |
return 0; |
| } |
} |