[LEDE-DEV,5/7] firmware-tools/ptgen: improve error messages on failures

Message ID 1513897174-20803-6-git-send-email-mhei@heimpold.de
State Changes Requested
Delegated to: John Crispin
Headers show
Series
  • firmware-tools/ptgen: minor fixes and improvements
Related show

Commit Message

Michael Heimpold Dec. 21, 2017, 10:59 p.m.
Signed-off-by: Michael Heimpold <mhei@heimpold.de>
---
 tools/firmware-utils/src/ptgen.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Patch

diff --git a/tools/firmware-utils/src/ptgen.c b/tools/firmware-utils/src/ptgen.c
index af14d73..3e1b8ba 100644
--- a/tools/firmware-utils/src/ptgen.c
+++ b/tools/firmware-utils/src/ptgen.c
@@ -30,6 +30,7 @@ 
 #include <ctype.h>
 #include <fcntl.h>
 #include <stdint.h>
+#include <errno.h>
 
 #if __BYTE_ORDER == __BIG_ENDIAN
 #define cpu_to_le32(x) bswap_32(x)
@@ -168,24 +169,24 @@  static int gen_ptable(uint32_t signature, int nr)
 	}
 
 	if ((fd = open(filename, O_WRONLY|O_CREAT, 0644)) < 0) {
-		fprintf(stderr, "Can't open output file '%s'\n",filename);
+		fprintf(stderr, "Can't open output file '%s': %s\n", filename, strerror(errno));
 		return -1;
 	}
 
 	lseek(fd, 440, SEEK_SET);
 	if (write(fd, &signature, sizeof(signature)) != sizeof(signature)) {
-		fprintf(stderr, "write failed.\n");
+		perror("Writing disk signature failed");
 		goto fail;
 	}
 
 	lseek(fd, 446, SEEK_SET);
 	if (write(fd, pte, sizeof(struct pte) * 4) != sizeof(struct pte) * 4) {
-		fprintf(stderr, "write failed.\n");
+		perror("Writing partition table failed");
 		goto fail;
 	}
 	lseek(fd, 510, SEEK_SET);
 	if (write(fd, "\x55\xaa", 2) != 2) {
-		fprintf(stderr, "write failed.\n");
+		perror("Writing signature failed");
 		goto fail;
 	}