aboutsummaryrefslogtreecommitdiffstats
path: root/samsung-ipc/utils.c
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2020-01-23 19:43:18 +0100
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2020-01-30 03:51:42 +0100
commit869ac6f4ebf069eda11d793591c252faf795fa04 (patch)
treebeaa6fe43bacc5bac665baaa3d47a4a36a72f621 /samsung-ipc/utils.c
parent0828f6aeb400d27f4c06050c7a4bb463fdf1d6b9 (diff)
downloadhardware_replicant_libsamsung-ipc-869ac6f4ebf069eda11d793591c252faf795fa04.tar.gz
hardware_replicant_libsamsung-ipc-869ac6f4ebf069eda11d793591c252faf795fa04.tar.bz2
hardware_replicant_libsamsung-ipc-869ac6f4ebf069eda11d793591c252faf795fa04.zip
file_data_{read,write}: Add logging
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
Diffstat (limited to 'samsung-ipc/utils.c')
-rw-r--r--samsung-ipc/utils.c76
1 files changed, 59 insertions, 17 deletions
diff --git a/samsung-ipc/utils.c b/samsung-ipc/utils.c
index 756d191..1bba874 100644
--- a/samsung-ipc/utils.c
+++ b/samsung-ipc/utils.c
@@ -32,9 +32,10 @@
#include <linux/netlink.h>
#include <net/if.h>
+#include <samsung-ipc.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 +44,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 +80,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;
@@ -83,8 +104,9 @@ complete:
return data;
}
-int file_data_write(const char *path, const void *data, size_t size,
- size_t chunk_size, unsigned int offset)
+int file_data_write(struct ipc_client *client, const char *path,
+ const void *data, size_t size, size_t chunk_size,
+ unsigned int offset)
{
int fd = -1;
size_t count;
@@ -92,24 +114,44 @@ int file_data_write(const char *path, const void *data, size_t size,
unsigned char *p;
int rc;
- if (path == NULL || data == NULL || size == 0 || chunk_size == 0 || chunk_size > size)
+ if (path == NULL || data == 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 -1;
+ }
fd = open(path, O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- if (fd < 0)
+ if (fd < 0) {
+ ipc_client_log(client, "%s: open failed with error %d", __FUNCTION__, fd);
goto error;
+ }
seek = lseek(fd, (off_t) offset, SEEK_SET);
- if (seek < (off_t) offset)
+ if (seek < (off_t) offset) {
+ ipc_client_log(client, "%s failed: seek < (off_t) offset", __FUNCTION__);
goto error;
+ }
p = (unsigned char *) data;
count = 0;
while (count < size) {
rc = write(fd, p, size - count > chunk_size ? chunk_size : size - count);
- if (rc <= 0)
- goto error;
+ if (rc <= 0) {
+ ipc_client_log(client, "%s: write failed with error %d", __FUNCTION__, rc);
+ goto error;
+ }
p += rc;
count += rc;