aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2019-07-17 18:03:19 +0200
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2019-09-12 17:48:09 +0200
commite2ae94408dea2a76393be923532d9e66dddc411d (patch)
tree093b7cae0174b8054ce63648511a87c10c0c46e4
parentcdaa993a1f153d49dfb31eb942660d41ed90c6bb (diff)
downloadhardware_replicant_libsamsung-ipc-e2ae94408dea2a76393be923532d9e66dddc411d.tar.gz
hardware_replicant_libsamsung-ipc-e2ae94408dea2a76393be923532d9e66dddc411d.tar.bz2
hardware_replicant_libsamsung-ipc-e2ae94408dea2a76393be923532d9e66dddc411d.zip
sync file_data_write with file_data_read
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rw-r--r--include/samsung-ipc.h5
-rw-r--r--samsung-ipc/utils.c41
2 files changed, 34 insertions, 12 deletions
diff --git a/include/samsung-ipc.h b/include/samsung-ipc.h
index 0b255b1..e3e6c4a 100644
--- a/include/samsung-ipc.h
+++ b/include/samsung-ipc.h
@@ -137,8 +137,9 @@ int ipc_rfs_message_setup(const struct ipc_rfs_header *header,
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 file_data_write(struct ipc_client *client,
+ 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);
int network_iface_down(const char *iface, int domain, int type);
int sysfs_value_read(const char *path);
diff --git a/samsung-ipc/utils.c b/samsung-ipc/utils.c
index bd1a55d..bca847d 100644
--- a/samsung-ipc/utils.c
+++ b/samsung-ipc/utils.c
@@ -32,6 +32,7 @@
#include <linux/netlink.h>
#include <net/if.h>
+#include <samsung-ipc.h>
void *file_data_read(struct ipc_client *client, const char *path, size_t size,
size_t chunk_size, unsigned int offset)
@@ -103,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;
@@ -112,24 +114,43 @@ 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)
- return -1;
+ 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)
- 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;
+ }
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: Error: rc < 0", __FUNCTION__);
+ goto error;
+ }
p += rc;
count += rc;