aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2021-02-17 00:18:41 +0100
committerDenis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>2021-03-04 00:15:16 +0100
commit1450acbb28acd83f8b46171d881c0d96f807140c (patch)
tree5bba79b7e4382b8779eaaf7ffe96f2d3d0953545
parent8b763fe3e6e184a84c298ca62073023f7273e250 (diff)
downloadhardware_replicant_libsamsung-ipc-1450acbb28acd83f8b46171d881c0d96f807140c.tar.gz
hardware_replicant_libsamsung-ipc-1450acbb28acd83f8b46171d881c0d96f807140c.tar.bz2
hardware_replicant_libsamsung-ipc-1450acbb28acd83f8b46171d881c0d96f807140c.zip
partitions: android: Add open_android_modem_partition_by_name
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
-rw-r--r--samsung-ipc/partitions/android/android.c63
-rw-r--r--samsung-ipc/partitions/android/android.h2
2 files changed, 65 insertions, 0 deletions
diff --git a/samsung-ipc/partitions/android/android.c b/samsung-ipc/partitions/android/android.c
index fb922c5..9ec6ed4 100644
--- a/samsung-ipc/partitions/android/android.c
+++ b/samsung-ipc/partitions/android/android.c
@@ -23,12 +23,20 @@
#include <errno.h>
#include <fcntl.h>
#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <samsung-ipc.h>
+static char const * const partitions_dirnames[] = {
+ "/dev/disk/by-partlabel/", /* GNU/Linux */
+ "/dev/block/by-name/", /* Android */
+ NULL
+};
+
int open_android_modem_partition(struct ipc_client *client,
char const * const *path_names)
{
@@ -54,3 +62,58 @@ int open_android_modem_partition(struct ipc_client *client,
errno = ENOENT;
return -1;
}
+
+int open_android_modem_partition_by_name(struct ipc_client *client,
+ const char *name, char **out_path)
+{
+ int i;
+ int rc;
+
+ for (i = 0; partitions_dirnames[i] != NULL; i++) {
+ char *path = NULL;
+ int fd;
+ size_t len;
+
+ len = strlen(partitions_dirnames[i]) + strlen(name) + 1;
+ path = calloc(1, len);
+ if (path == NULL) {
+ rc = errno;
+ ipc_client_log(client,
+ "%s: calloc failed with error %d: %s",
+ __func__, rc, strerror(rc));
+ return -errno;
+ }
+
+ strncpy(path, partitions_dirnames[i],
+ strlen(partitions_dirnames[i]));
+ strcat(path, name);
+
+ ipc_client_log(client, "%s: Trying to open %s",
+ __func__, path);
+
+ fd = open(path, O_RDONLY);
+ if (fd == -1) {
+ rc = -errno;
+ if (out_path)
+ *out_path = path;
+ else
+ free(path);
+
+ if (rc == -ENOENT)
+ continue;
+
+ errno = -rc;
+ return -1;
+ }
+
+ if (out_path)
+ *out_path = path;
+ else
+ free(path);
+
+ return fd;
+ }
+
+ errno = ENOENT;
+ return -1;
+}
diff --git a/samsung-ipc/partitions/android/android.h b/samsung-ipc/partitions/android/android.h
index 4d7700c..e2f23f7 100644
--- a/samsung-ipc/partitions/android/android.h
+++ b/samsung-ipc/partitions/android/android.h
@@ -24,4 +24,6 @@
#define __ANDROID_PARTITIONS_H__
int open_android_modem_partition(struct ipc_client *client,
char const * const *path_names);
+int open_android_modem_partition_by_name(struct ipc_client *client,
+ const char *name, char **out_path);
#endif /* __ANDROID_PARTITIONS_H__ */