f3brew: handle lack of access right

When a non-root user called f3brew on a device,
f3brew would issue the following error message:

Your username doesn't have access to device `/dev/sdc'.
Try to run this program as root:
sudo f3probe /dev/sdc
In case you don't have access to root, use f3write/f3read.
f3brew: f3brew.c:484: main: Assertion `dev' failed.
Aborted (core dumped)

This patch avoids the assert().
This commit is contained in:
Michel Machado 2015-10-09 19:29:10 -04:00
parent 8305e5ad5f
commit c47a7642fb

View File

@ -1,4 +1,5 @@
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <assert.h>
#include <string.h>
@ -481,7 +482,10 @@ int main(int argc, char **argv)
args.fake_size_byte, args.wrap, args.block_order,
args.keep_file)
: create_block_device(args.filename, args.reset_type);
assert(dev);
if (!dev) {
fprintf(stderr, "\nApplication cannot continue, finishing...\n");
exit(1);
}
printf("Physical block size: 2^%i Bytes\n\n", dev_get_block_order(dev));