From 78f71fc2df35d4f0d259bb7a2591f7c61076ca12 Mon Sep 17 00:00:00 2001 From: Denis 'GNUtoo' Carikli Date: Mon, 31 Aug 2020 18:05:15 +0200 Subject: samsung-ipc: utils.c: file_data_{read,write}: report open error Mounting the EFS on your local computer can result in user id and permissions mismatch because the /etc/fstab doesn't always match the user ids used by Android. For instance here's the GT-N7000 EFS on my laptop: $ ls -l [...]/nv_data.bin -rwx------ 1 1001 1001 2097152 1 janv. 2000 [...]/nv_data.bin When using nv_data-md5 on it we have: $ ./tools/nv_data-md5 [...]/nv_data.bin [ipc] file_data_read: Error: fd: -1 [ipc] ipc_nv_data_md5_calculate failed: data is NULL Calculating nv_data backup md5 failed The error was too cryptic, and I ended up having to dig into the source code to understand what was going on. With this patch we now have an error message that is easier to understand: $ ./tools/nv_data-md5 [...]/nv_data.bin [ipc] file_data_read open failed with error 13: Permission denied [ipc] ipc_nv_data_md5_calculate failed: data is NULL Calculating nv_data backup md5 failed Signed-off-by: Denis 'GNUtoo' Carikli --- samsung-ipc/utils.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/samsung-ipc/utils.c b/samsung-ipc/utils.c index 85f06cf..0e6bc2f 100644 --- a/samsung-ipc/utils.c +++ b/samsung-ipc/utils.c @@ -18,6 +18,7 @@ */ #include +#include #include #include #include @@ -70,7 +71,9 @@ void *file_data_read(struct ipc_client *client, const char *path, size_t size, fd = open(path, O_RDONLY); if (fd < 0) { - ipc_client_log(client, "%s: Error: fd: %d ", __func__, fd); + rc = errno; + ipc_client_log(client, "%s open failed with error %d: %s", __func__, rc, + strerror(rc)); goto error; } @@ -147,8 +150,9 @@ int file_data_write(struct ipc_client *client, const char *path, fd = open(path, O_WRONLY | O_CREAT, 0644); if (fd < 0) { - ipc_client_log(client, "%s: open failed with error %d", - __func__, fd); + rc = errno; + ipc_client_log(client, "%s open failed with error %d: %s", + __func__, rc, strerror(rc)); goto error; } -- cgit v1.2.3