aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2019-07-17 17:58:02 +0200
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2019-09-12 17:48:09 +0200
commitcdaa993a1f153d49dfb31eb942660d41ed90c6bb (patch)
treea487bab7d359d01c9507658db1c8737ae5bd27d4
parent6f36381ff5b5a1c28cd6c00791d4093f1a63e38d (diff)
downloadhardware_replicant_libsamsung-ipc-cdaa993a1f153d49dfb31eb942660d41ed90c6bb.tar.gz
hardware_replicant_libsamsung-ipc-cdaa993a1f153d49dfb31eb942660d41ed90c6bb.tar.bz2
hardware_replicant_libsamsung-ipc-cdaa993a1f153d49dfb31eb942660d41ed90c6bb.zip
file_data_read: add logging
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rw-r--r--include/samsung-ipc.h5
-rw-r--r--samsung-ipc/devices/aries/aries.c2
-rw-r--r--samsung-ipc/devices/crespo/crespo.c2
-rw-r--r--samsung-ipc/devices/maguro/maguro.c2
-rw-r--r--samsung-ipc/rfs.c28
-rw-r--r--samsung-ipc/utils.c40
6 files changed, 50 insertions, 29 deletions
diff --git a/include/samsung-ipc.h b/include/samsung-ipc.h
index 9d638ec..0b255b1 100644
--- a/include/samsung-ipc.h
+++ b/include/samsung-ipc.h
@@ -134,8 +134,9 @@ int ipc_rfs_header_setup(struct ipc_rfs_header *header,
int ipc_rfs_message_setup(const struct ipc_rfs_header *header,
struct ipc_message *message);
-void *file_data_read(const char *path, size_t size, size_t chunk_size,
- unsigned int offset);
+void *file_data_read(struct ipc_client *client,
+ const char *path, size_t size, size_t chunk_size,
+ unsigned int offset);
int file_data_write(const char *path, const void *data, size_t size,
size_t chunk_size, unsigned int offset);
int network_iface_up(const char *iface, int domain, int type);
diff --git a/samsung-ipc/devices/aries/aries.c b/samsung-ipc/devices/aries/aries.c
index a3da208..e41a4e2 100644
--- a/samsung-ipc/devices/aries/aries.c
+++ b/samsung-ipc/devices/aries/aries.c
@@ -62,7 +62,7 @@ int aries_boot(struct ipc_client *client)
ipc_client_log(client, "Starting aries modem boot");
- modem_image_data = file_data_read(ARIES_MODEM_IMAGE_DEVICE, ARIES_MODEM_IMAGE_SIZE, 0x1000, 0);
+ modem_image_data = file_data_read(client, ARIES_MODEM_IMAGE_DEVICE, ARIES_MODEM_IMAGE_SIZE, 0x1000, 0);
if (modem_image_data == NULL) {
ipc_client_log(client, "Reading modem image data failed");
goto error;
diff --git a/samsung-ipc/devices/crespo/crespo.c b/samsung-ipc/devices/crespo/crespo.c
index 1bf9a97..612ce5d 100644
--- a/samsung-ipc/devices/crespo/crespo.c
+++ b/samsung-ipc/devices/crespo/crespo.c
@@ -50,7 +50,7 @@ int crespo_boot(struct ipc_client *client)
ipc_client_log(client, "Starting crespo modem boot");
- modem_image_data = file_data_read(CRESPO_MODEM_IMAGE_DEVICE, CRESPO_MODEM_IMAGE_SIZE, 0x1000, 0);
+ modem_image_data = file_data_read(client, CRESPO_MODEM_IMAGE_DEVICE, CRESPO_MODEM_IMAGE_SIZE, 0x1000, 0);
if (modem_image_data == NULL) {
ipc_client_log(client, "Reading modem image data failed");
goto error;
diff --git a/samsung-ipc/devices/maguro/maguro.c b/samsung-ipc/devices/maguro/maguro.c
index b41eadd..76eac54 100644
--- a/samsung-ipc/devices/maguro/maguro.c
+++ b/samsung-ipc/devices/maguro/maguro.c
@@ -140,7 +140,7 @@ int maguro_boot(struct ipc_client *client)
}
ipc_client_log(client, "Sent XMM626 MIPI nv_data");
- mps_data = file_data_read(MAGURO_MPS_DATA_DEVICE, MAGURO_MPS_DATA_SIZE, MAGURO_MPS_DATA_SIZE, 0);
+ mps_data = file_data_read(client, MAGURO_MPS_DATA_DEVICE, MAGURO_MPS_DATA_SIZE, MAGURO_MPS_DATA_SIZE, 0);
if (mps_data == NULL) {
ipc_client_log(client, "Reading MPS data failed");
goto error;
diff --git a/samsung-ipc/rfs.c b/samsung-ipc/rfs.c
index dc1a03f..4dd8203 100644
--- a/samsung-ipc/rfs.c
+++ b/samsung-ipc/rfs.c
@@ -46,7 +46,7 @@ char *ipc_nv_data_md5_calculate(struct ipc_client *client,
return NULL;
}
- data = file_data_read(path, size, chunk_size, 0);
+ data = file_data_read(client, path, size, chunk_size, 0);
if (data == NULL) {
ipc_client_log(client, "%s: Failed: data is NULL", __FUNCTION__);
return NULL;
@@ -232,7 +232,7 @@ int ipc_nv_data_check(struct ipc_client *client)
length = strlen(md5_string);
- buffer = file_data_read(md5_path, length, length, 0);
+ buffer = file_data_read(client, md5_path, length, length, 0);
if (buffer == NULL) {
ipc_client_log(client, "Reading nv_data md5 failed");
goto error;
@@ -312,7 +312,7 @@ int ipc_nv_data_backup_check(struct ipc_client *client)
length = strlen(backup_md5_string);
- buffer = file_data_read(backup_md5_path, length, length, 0);
+ buffer = file_data_read(client, backup_md5_path, length, length, 0);
if (buffer == NULL) {
ipc_client_log(client, "Reading nv_data backup md5 failed");
goto error;
@@ -378,7 +378,7 @@ int ipc_nv_data_backup(struct ipc_client *client)
goto error;
}
- data = file_data_read(path, size, chunk_size, 0);
+ data = file_data_read(client, path, size, chunk_size, 0);
if (data == NULL) {
ipc_client_log(client, "Reading nv_data failed");
goto error;
@@ -397,7 +397,7 @@ int ipc_nv_data_backup(struct ipc_client *client)
if (rc < 0)
ipc_client_log(client, "Removing nv_data backup path failed");
- rc = file_data_write(backup_path, data, size, chunk_size, 0);
+ rc = file_data_write(client, backup_path, data, size, chunk_size, 0);
if (rc < 0) {
ipc_client_log(client, "Writing nv_data backup failed");
goto error;
@@ -407,7 +407,7 @@ int ipc_nv_data_backup(struct ipc_client *client)
if (rc < 0)
ipc_client_log(client, "Removing nv_data backup md5 path failed");
- rc = file_data_write(backup_md5_path, md5_string, length, length, 0);
+ rc = file_data_write(client, backup_md5_path, md5_string, length, length, 0);
if (rc < 0) {
ipc_client_log(client, "Writing nv_data backup md5 failed");
goto error;
@@ -463,7 +463,7 @@ int ipc_nv_data_restore(struct ipc_client *client)
goto error;
}
- data = file_data_read(backup_path, size, chunk_size, 0);
+ data = file_data_read(client, backup_path, size, chunk_size, 0);
if (data == NULL) {
ipc_client_log(client, "Reading nv_data backup failed");
goto error;
@@ -473,7 +473,7 @@ int ipc_nv_data_restore(struct ipc_client *client)
if (rc < 0)
ipc_client_log(client, "Removing nv_data path failed");
- rc = file_data_write(path, data, size, chunk_size, 0);
+ rc = file_data_write(client, path, data, size, chunk_size, 0);
if (rc < 0) {
ipc_client_log(client, "Writing nv_data failed");
goto error;
@@ -484,7 +484,7 @@ int ipc_nv_data_restore(struct ipc_client *client)
length = 2 * sizeof(char) * MD5_DIGEST_LENGTH;
- data = file_data_read(backup_md5_path, length, length, 0);
+ data = file_data_read(client, backup_md5_path, length, length, 0);
if (data == NULL) {
ipc_client_log(client, "Reading nv_data backup md5 failed");
goto error;
@@ -494,7 +494,7 @@ int ipc_nv_data_restore(struct ipc_client *client)
if (rc < 0)
ipc_client_log(client, "Removing nv_data md5 path failed");
- rc = file_data_write(md5_path, data, length, length, 0);
+ rc = file_data_write(client, md5_path, data, length, length, 0);
if (rc < 0) {
ipc_client_log(client, "Writing nv_data md5 failed");
goto error;
@@ -561,7 +561,7 @@ void *ipc_nv_data_load(struct ipc_client *client)
ipc_client_log(client, "Backing up nv_data failed");
}
- data = file_data_read(path, size, chunk_size, 0);
+ data = file_data_read(client, path, size, chunk_size, 0);
if (data == NULL) {
ipc_client_log(client, "Reading nv_data failed");
return NULL;
@@ -593,7 +593,7 @@ void *ipc_nv_data_read(struct ipc_client *client, size_t size,
return NULL;
}
- data = file_data_read(path, size, chunk_size > size ? size : chunk_size, offset);
+ data = file_data_read(client, path, size, chunk_size > size ? size : chunk_size, offset);
if (data == NULL) {
ipc_client_log(client, "Reading nv_data failed");
return NULL;
@@ -630,7 +630,7 @@ int ipc_nv_data_write(struct ipc_client *client, const void *data, size_t size,
goto error;
}
- rc = file_data_write(path, data, size, chunk_size > size ? size : chunk_size, offset);
+ rc = file_data_write(client, path, data, size, chunk_size > size ? size : chunk_size, offset);
if (rc < 0) {
ipc_client_log(client, "Writing nv_data failed");
goto error;
@@ -655,7 +655,7 @@ int ipc_nv_data_write(struct ipc_client *client, const void *data, size_t size,
goto error;
}
- rc = file_data_write(md5_path, md5_string, length, length, 0);
+ rc = file_data_write(client, md5_path, md5_string, length, length, 0);
if (rc < 0) {
ipc_client_log(client, "Writing nv_data md5 failed");
goto error;
diff --git a/samsung-ipc/utils.c b/samsung-ipc/utils.c
index 756d191..bd1a55d 100644
--- a/samsung-ipc/utils.c
+++ b/samsung-ipc/utils.c
@@ -33,8 +33,8 @@
#include <net/if.h>
-void *file_data_read(const char *path, size_t size, size_t chunk_size,
- unsigned int offset)
+void *file_data_read(struct ipc_client *client, const char *path, size_t size,
+ size_t chunk_size, unsigned int offset)
{
void *data = NULL;
int fd = -1;
@@ -43,16 +43,34 @@ void *file_data_read(const char *path, size_t size, size_t chunk_size,
unsigned char *p;
int rc;
- if (path == NULL || size == 0 || chunk_size == 0 || chunk_size > size)
- return NULL;
+ if (path == NULL || size == 0 || chunk_size == 0 || chunk_size > size) {
+ if (path == NULL) {
+ ipc_client_log(client, "%s: Failed: path is NULL", __FUNCTION__);
+ }
+ if (size == 0) {
+ ipc_client_log(client, "%s: Failed: size is 0", __FUNCTION__);
+ }
+ if (chunk_size == 0) {
+ ipc_client_log(client, "%s: Failed: chunk_size is 0", __FUNCTION__);
+ }
+ if (chunk_size > size) {
+ ipc_client_log(client, "%s: Failed: chunk_size > size ", __FUNCTION__);
+ }
+
+ return NULL;
+ }
fd = open(path, O_RDONLY);
- if (fd < 0)
- goto error;
+ if (fd < 0) {
+ ipc_client_log(client, "%s: Error: fd: %d ", __FUNCTION__, fd);
+ goto error;
+ }
seek = lseek(fd, (off_t) offset, SEEK_SET);
- if (seek < (off_t) offset)
- goto error;
+ if (seek < (off_t) offset) {
+ ipc_client_log(client, "%s: Error: seek < (off_t) offset", __FUNCTION__);
+ goto error;
+ }
data = calloc(1, size);
@@ -61,8 +79,10 @@ void *file_data_read(const char *path, size_t size, size_t chunk_size,
count = 0;
while (count < size) {
rc = read(fd, p, size - count > chunk_size ? chunk_size : size - count);
- if (rc <= 0)
- goto error;
+ if (rc <= 0) {
+ ipc_client_log(client, "%s: Error: rc < 0", __FUNCTION__);
+ goto error;
+ }
p += rc;
count += rc;