[Replicant] [libsamsung-ipc] [PATCH 2/2] samsung-ipc: utils.c: file_data_{read, write}: report open error
Denis 'GNUtoo' Carikli
GNUtoo at cyberdimension.org
Mon Aug 31 16:14:29 UTC 2020
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 <GNUtoo at cyberdimension.org>
---
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 c92fc36..7a84764 100644
--- a/samsung-ipc/utils.c
+++ b/samsung-ipc/utils.c
@@ -18,6 +18,7 @@
*/
#include <ctype.h>
+#include <errno.h>
#include <fcntl.h>
#include <stdint.h>
#include <stdio.h>
@@ -68,7 +69,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;
}
@@ -145,8 +148,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;
}
--
2.28.0
More information about the Replicant
mailing list