Message ID | 20161028032825.27907-1-joel@jms.id.au |
---|---|
State | Accepted |
Headers | show |
On Fri, 2016-10-28 at 13:58 +1030, Joel Stanley wrote: > Currently we warn the user and truncate the file by default. Instead > abort as this is rarely the desired behaviour. > > You can still shoot yourself in the foot by passing --force. > > Signed-off-by: Joel Stanley <joel@jms.id.au> > --- > > Compile tested only > > external/pflash/pflash.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c > index 89bd2fe73a04..c93bbd4533bb 100644 > --- a/external/pflash/pflash.c > +++ b/external/pflash/pflash.c > @@ -839,14 +839,20 @@ int main(int argc, char *argv[]) > if (!write_size) > write_size = pmaxsz; > > - /* Crop write size to partition size */ > - if (write_size > pmaxsz) { > + /* Crop write size to partition size if --force was > passed */ > + if (write_size > pmaxsz && !must_confirm) { > printf("WARNING: Size (%d bytes) larger than > partition" > " (%d bytes), cropping to fit\n", > write_size, pmaxsz); > write_size = pmaxsz; > + } else if (write_size > pmaxsz) { > + printf("ERROR: Size (%d bytes) larger than > partition" > + " (%d bytes). Use --force to > force\n", > + write_size, pmaxsz); > + exit(1); > } > > + > /* If erasing, check partition alignment */ > if (erase && ((pstart | pmaxsz) & 0xfff)) { > fprintf(stderr,"Partition not aligned > properly\n");
On Fri, 2016-10-28 at 13:58 +1030, Joel Stanley wrote: > Currently we warn the user and truncate the file by default. Instead > abort as this is rarely the desired behaviour. > > You can still shoot yourself in the foot by passing --force. > Lets all enjoy that I didn't actually type anything last time... Joels code is always perfect though :). Tested on palmetto trying to flash a skiboot.lid which was too big and a skiboot.lid.xz. > Signed-off-by: Joel Stanley <joel@jms.id.au> Reviewed-by: Cyril Bur <cyril.bur@au1.ibm.com> > --- > > Compile tested only > > external/pflash/pflash.c | 10 ++++++++-- > 1 file changed, 8 insertions(+), 2 deletions(-) > > diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c > index 89bd2fe73a04..c93bbd4533bb 100644 > --- a/external/pflash/pflash.c > +++ b/external/pflash/pflash.c > @@ -839,14 +839,20 @@ int main(int argc, char *argv[]) > if (!write_size) > write_size = pmaxsz; > > - /* Crop write size to partition size */ > - if (write_size > pmaxsz) { > + /* Crop write size to partition size if --force was > passed */ > + if (write_size > pmaxsz && !must_confirm) { > printf("WARNING: Size (%d bytes) larger than > partition" > " (%d bytes), cropping to fit\n", > write_size, pmaxsz); > write_size = pmaxsz; > + } else if (write_size > pmaxsz) { > + printf("ERROR: Size (%d bytes) larger than > partition" > + " (%d bytes). Use --force to > force\n", > + write_size, pmaxsz); > + exit(1); > } > > + > /* If erasing, check partition alignment */ > if (erase && ((pstart | pmaxsz) & 0xfff)) { > fprintf(stderr,"Partition not aligned > properly\n");
Joel Stanley <joel@jms.id.au> writes: > Currently we warn the user and truncate the file by default. Instead > abort as this is rarely the desired behaviour. > > You can still shoot yourself in the foot by passing --force. > > Signed-off-by: Joel Stanley <joel@jms.id.au> > --- > > Compile tested only Seems to work... and Cyril reviewed it, so merged to master as of 4382d472a517d6a39f919b139eed3c86c6db9009
On Wed, Nov 2, 2016 at 6:15 PM, Stewart Smith <stewart@linux.vnet.ibm.com> wrote: >> >> Compile tested only > > ... Cyril reviewed it ... The gold standard really. Cheers, Joel
diff --git a/external/pflash/pflash.c b/external/pflash/pflash.c index 89bd2fe73a04..c93bbd4533bb 100644 --- a/external/pflash/pflash.c +++ b/external/pflash/pflash.c @@ -839,14 +839,20 @@ int main(int argc, char *argv[]) if (!write_size) write_size = pmaxsz; - /* Crop write size to partition size */ - if (write_size > pmaxsz) { + /* Crop write size to partition size if --force was passed */ + if (write_size > pmaxsz && !must_confirm) { printf("WARNING: Size (%d bytes) larger than partition" " (%d bytes), cropping to fit\n", write_size, pmaxsz); write_size = pmaxsz; + } else if (write_size > pmaxsz) { + printf("ERROR: Size (%d bytes) larger than partition" + " (%d bytes). Use --force to force\n", + write_size, pmaxsz); + exit(1); } + /* If erasing, check partition alignment */ if (erase && ((pstart | pmaxsz) & 0xfff)) { fprintf(stderr,"Partition not aligned properly\n");
Currently we warn the user and truncate the file by default. Instead abort as this is rarely the desired behaviour. You can still shoot yourself in the foot by passing --force. Signed-off-by: Joel Stanley <joel@jms.id.au> --- Compile tested only external/pflash/pflash.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-)