From fa5e28bf7c9c762dd294cc9beabaf310dc4f23b7 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Tue, 23 Jul 2019 16:51:41 +0900 Subject: [PATCH 01/16] Add comment for privacy-related privilege Change-Id: I2187c3930838364ff3afe8364a0ee99a2e4431d7 Signed-off-by: Yunmi Ha --- include/storage-expand.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/include/storage-expand.h b/include/storage-expand.h index 9cf079b..e519566 100644 --- a/include/storage-expand.h +++ b/include/storage-expand.h @@ -109,6 +109,7 @@ int storage_foreach_device_supported(storage_device_supported_cb callback, void * When an application is uninstalled, the files written by that application are not removed from the internal/external storage.\n * If you want to access files or directories in internal storage, you must declare http://tizen.org/privilege/mediastorage.\n * If you want to access files or directories in external storage, you must declare http://tizen.org/privilege/externalstorage.\n + * Refer to Privacy-related Permissions.\n * You must release @a path using free(). * @param[in] storage_id The storage device * @param[out] path The absolute path to the storage directory @@ -148,9 +149,9 @@ typedef enum { * @remarks Files saved on the internal/external storage are readable or writable by all applications.\n * When an application is uninstalled, the files written by that application are not removed from the internal/external storage.\n * The directory path may not exist, so you must make sure that it exists before using it.\n - * If you want to access files or directories in internal storage except #STORAGE_DIRECTORY_SYSTEM_RINGTONES, you must declare http://tizen.org/privilege/mediastorage.\n - * If you want to access files or directories in #STORAGE_DIRECTORY_SYSTEM_RINGTONES, you must declare %http://tizen.org/privilege/systemsettings.\n + * If you want to access files or directories in internal storage, you must declare http://tizen.org/privilege/mediastorage.\n * If you want to access files or directories in external storage, you must declare http://tizen.org/privilege/externalstorage.\n + * Refer to Privacy-related Permissions.\n * You must release @a path using free(). * @param[in] storage_id The storage device * @param[in] type The directory type -- 2.7.4 From 6962c4b2b42131604bbc78cf67fe703140868747 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Wed, 24 Jul 2019 14:35:55 +0900 Subject: [PATCH 02/16] Change reference page url Change-Id: I3a4217159e4ce9f5981980dd2cc99c71a45c4f01 Signed-off-by: Yunmi Ha --- include/storage-expand.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/storage-expand.h b/include/storage-expand.h index e519566..2be363e 100644 --- a/include/storage-expand.h +++ b/include/storage-expand.h @@ -109,7 +109,7 @@ int storage_foreach_device_supported(storage_device_supported_cb callback, void * When an application is uninstalled, the files written by that application are not removed from the internal/external storage.\n * If you want to access files or directories in internal storage, you must declare http://tizen.org/privilege/mediastorage.\n * If you want to access files or directories in external storage, you must declare http://tizen.org/privilege/externalstorage.\n - * Refer to Privacy-related Permissions.\n + * Refer to Privacy-related Permissions.\n * You must release @a path using free(). * @param[in] storage_id The storage device * @param[out] path The absolute path to the storage directory @@ -151,7 +151,7 @@ typedef enum { * The directory path may not exist, so you must make sure that it exists before using it.\n * If you want to access files or directories in internal storage, you must declare http://tizen.org/privilege/mediastorage.\n * If you want to access files or directories in external storage, you must declare http://tizen.org/privilege/externalstorage.\n - * Refer to Privacy-related Permissions.\n + * Refer to Privacy-related Permissions.\n * You must release @a path using free(). * @param[in] storage_id The storage device * @param[in] type The directory type -- 2.7.4 From 0478a77b0719e3eaed6e0829d3a4959700fbc669 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Thu, 12 Dec 2019 17:37:19 +0900 Subject: [PATCH 03/16] Change "developer.tizen.org" link to "docs.tizen.org" Change-Id: I9349eac4b09a42df7360a0bcff2bbc5363eaa1aa Signed-off-by: Yunmi Ha --- doc/storage_doc.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/storage_doc.h b/doc/storage_doc.h index 0260fa3..f45144a 100755 --- a/doc/storage_doc.h +++ b/doc/storage_doc.h @@ -56,7 +56,7 @@ * * To ensure your application is only running on the device with specific features, please define the features in your manifest file using the manifest editor in the SDK.\n * - * More details on featuring your application can be found from feature element description. + * More details on featuring your application can be found from feature element description. * * */ -- 2.7.4 From a57c5f01be052d85a4f3f99223239a69abecd6bf Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Fri, 27 Dec 2019 17:32:31 +0900 Subject: [PATCH 04/16] Remove 'format-truncation' warning for GCC-9 Change-Id: I561072c619f169309d66dde7a1946664b8d55935 Signed-off-by: Yunmi Ha --- src/storage.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/storage.c b/src/storage.c index 314f622..6778dff 100644 --- a/src/storage.c +++ b/src/storage.c @@ -218,8 +218,12 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p *end = '\0'; snprintf(temp, PATH_MAX, "%s", temp2); free(temp2); - } else - snprintf(temp, PATH_MAX, "%s/%s", root, dir_path[type]); + } else { + if ((ret = snprintf(temp, PATH_MAX, "%s/%s", root, dir_path[type])) > PATH_MAX - 1) { + _E("Path is longer than buffer. Need %d size of buffer.", ret + 1); + return STORAGE_ERROR_OUT_OF_MEMORY; + } + } goto out; } @@ -249,7 +253,10 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p if (extendedint) return STORAGE_ERROR_INVALID_PARAMETER; - snprintf(temp, sizeof(temp), "%s/%s", root, dir_path[type]); + if ((ret = snprintf(temp, sizeof(temp), "%s/%s", root, dir_path[type])) > sizeof(temp) - 1) { + _E("Path is longer than buffer. Need %d size of buffer.", ret + 1); + return STORAGE_ERROR_OUT_OF_MEMORY; + } out: *path = strdup(temp); -- 2.7.4 From c18ba807bb1f46ec0125e3941af044060026dd8c Mon Sep 17 00:00:00 2001 From: Slava Barinov Date: Thu, 7 May 2020 13:13:52 +0300 Subject: [PATCH 05/16] Fix stringop-truncation error src/statvfs.c:121:4: error: 'strncpy' specified bound 64 equals destination size [-Werror=stringop-truncation] Change-Id: I328d339e73aeaff2c34db5531b0a3a30ece8f0ed Signed-off-by: Slava Barinov --- src/statvfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/statvfs.c b/src/statvfs.c index 976e1d0..e7e9e56 100644 --- a/src/statvfs.c +++ b/src/statvfs.c @@ -118,7 +118,7 @@ static int config_parse(const char *file_name, int cb(struct parse_result *resul } *end = '\0'; - strncpy(section, start + 1, sizeof(section)); + strncpy(section, start + 1, sizeof(section) - 1); section[MAX_SECTION-1] = '\0'; } else if (*start) { /* parse name & value */ -- 2.7.4 From 0c08cb3efdb14001e096f55af1241b936ebf53ab Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Wed, 20 May 2020 16:37:30 +0900 Subject: [PATCH 06/16] Support gcov build option Change-Id: I8160fd8004ea29200d968a7ddfadd396ae303a6f Signed-off-by: Yunmi Ha --- packaging/libstorage.spec | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/packaging/libstorage.spec b/packaging/libstorage.spec index 2a5d891..849064d 100644 --- a/packaging/libstorage.spec +++ b/packaging/libstorage.spec @@ -16,6 +16,9 @@ BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(mount) BuildRequires: pkgconfig(blkid) BuildRequires: pkgconfig(capi-system-info) +%if 0%{?gcov:1} +BuildRequires: lcov +%endif %description development package of library to get storage @@ -28,17 +31,40 @@ Requires: %{name} = %{version}-%{release} %description devel Library to get storage information (devel) +%if 0%{?gcov:1} +%package gcov +Summary: Get storage information (gcov) +Group: Development/Libraries +%description gcov +Library to get storage information (gcov) +%endif + %prep %setup -q cp %{SOURCE1} . %build +%if 0%{?gcov:1} +export CFLAGS+=" -fprofile-arcs -ftest-coverage" +export LDFLAGS+=" -lgcov" +%endif + %cmake . make %{?jobs:-j%jobs} +%if 0%{?gcov:1} +mkdir -p gcov-obj +find . -name '*.gcno' -exec cp '{}' gcov-obj ';' +%endif + %install %make_install +%if 0%{?gcov:1} +mkdir -p %{buildroot}%{_datadir}/gcov/obj +install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj +%endif + %post -p /sbin/ldconfig %postun -p /sbin/ldconfig @@ -55,3 +81,8 @@ make %{?jobs:-j%jobs} %{_includedir}/storage/*.h %{_libdir}/*.so %{_libdir}/pkgconfig/*.pc + +%if 0%{?gcov:1} +%files gcov +%{_datadir}/gcov/* +%endif -- 2.7.4 From bd2b9003e49da4176b3b58c083f6616aac6443b3 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Wed, 23 Sep 2020 17:07:00 +0900 Subject: [PATCH 07/16] Fix memory leak -After call g_variant_get function with string format, should call free. Change-Id: I6d2f74e4aaf920030ae3b691ea6705fb6f8623cf Signed-off-by: Yunmi Ha --- src/storage-external-dbus.c | 2 ++ src/storage-inhouse.c | 38 ++++++++++++++++++++++++-------------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index 5d45189..731296a 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -395,6 +395,8 @@ int storage_ext_get_storage_level(const char *path, char **level) g_variant_get(result, "(s)", &tmp); *level = strdup(tmp); + g_free(tmp); + if (*level == NULL) return -ENOMEM; diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index 2ec6f08..b35c4fb 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -164,7 +164,9 @@ API int storage_get_origin_internal_path(const char* compat, int len, char* orig API int storage_get_primary_sdcard(int *storage_id, char **path) { GVariant *result; - storage_ext_device info; + int ret; + char *mount_point = NULL; + int id; if (!storage_id || !path) return STORAGE_ERROR_INVALID_PARAMETER; @@ -185,25 +187,33 @@ API int storage_get_primary_sdcard(int *storage_id, char **path) } g_variant_get(result, "(issssssisibii)", - &info.type, &info.devnode, &info.syspath, - &info.fs_usage, &info.fs_type, - &info.fs_version, &info.fs_uuid, - &info.readonly, &info.mount_point, - &info.state, &info.primary, - &info.flags, &info.storage_id); + NULL, NULL, NULL, + NULL, NULL, + NULL, NULL, + NULL, &mount_point, + NULL, NULL, + NULL, &id); g_variant_unref(result); - if (info.storage_id < 0) - return STORAGE_ERROR_NO_DEVICE; + if (id < 0) { + ret = STORAGE_ERROR_NO_DEVICE; + goto out; + } - *path = strdup(info.mount_point); - if (*path == NULL) - return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE System Error + *path = strdup(mount_point); + if (*path == NULL) { + ret = STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE System Error + goto out; + } - *storage_id = info.storage_id; + *storage_id = id; - return STORAGE_ERROR_NONE; + ret = STORAGE_ERROR_NONE; +out: + g_free(mount_point); + + return ret; } API int storage_get_storage_level(const char *path, char **level) -- 2.7.4 From 8e56c944a995ba04f3531761381b7c50407948a3 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Wed, 16 Dec 2020 20:18:27 +0900 Subject: [PATCH 08/16] Removing unnecessary HTML link for privilege Change-Id: I3ee33cb216716d8dc8efa7b93af5cdf6d378d08d Signed-off-by: Yunmi Ha --- include/storage-expand.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/storage-expand.h b/include/storage-expand.h index 2be363e..dbc24c3 100644 --- a/include/storage-expand.h +++ b/include/storage-expand.h @@ -107,8 +107,8 @@ int storage_foreach_device_supported(storage_device_supported_cb callback, void * @since_tizen @if MOBILE 2.3 @elseif WEARABLE 2.3.1 @endif * @remarks Files saved on the internal/external storage are readable or writable by all applications.\n * When an application is uninstalled, the files written by that application are not removed from the internal/external storage.\n - * If you want to access files or directories in internal storage, you must declare http://tizen.org/privilege/mediastorage.\n - * If you want to access files or directories in external storage, you must declare http://tizen.org/privilege/externalstorage.\n + * If you want to access files or directories in internal storage, you must declare %http://tizen.org/privilege/mediastorage.\n + * If you want to access files or directories in external storage, you must declare %http://tizen.org/privilege/externalstorage.\n * Refer to Privacy-related Permissions.\n * You must release @a path using free(). * @param[in] storage_id The storage device @@ -149,8 +149,8 @@ typedef enum { * @remarks Files saved on the internal/external storage are readable or writable by all applications.\n * When an application is uninstalled, the files written by that application are not removed from the internal/external storage.\n * The directory path may not exist, so you must make sure that it exists before using it.\n - * If you want to access files or directories in internal storage, you must declare http://tizen.org/privilege/mediastorage.\n - * If you want to access files or directories in external storage, you must declare http://tizen.org/privilege/externalstorage.\n + * If you want to access files or directories in internal storage, you must declare %http://tizen.org/privilege/mediastorage.\n + * If you want to access files or directories in external storage, you must declare %http://tizen.org/privilege/externalstorage.\n * Refer to Privacy-related Permissions.\n * You must release @a path using free(). * @param[in] storage_id The storage device -- 2.7.4 From 7c94135186c55ce211e1c4aa65e9e2387e48df57 Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Wed, 6 Jan 2021 20:32:41 +0900 Subject: [PATCH 09/16] Use libsyscommon - list, ini-parser, dbus Change-Id: Iaf8b4dfa551118461aae25d1d654e7ec136567ec Signed-off-by: Yunmi Ha --- CMakeLists.txt | 1 + include/list.h | 68 ------------ packaging/libstorage.spec | 1 + src/statvfs.c | 110 +----------------- src/storage-external-dbus.c | 264 +++++++++++--------------------------------- src/storage-external-dbus.h | 13 +-- src/storage-external.c | 34 +++--- src/storage-inhouse.c | 17 +-- src/storage.c | 58 +++++----- 9 files changed, 124 insertions(+), 442 deletions(-) delete mode 100644 include/list.h diff --git a/CMakeLists.txt b/CMakeLists.txt index cbdb21f..539311a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ SET(dependents mount blkid capi-system-info + libsyscommon ) SET(pc_dependents "capi-base-common") diff --git a/include/list.h b/include/list.h deleted file mode 100644 index 27cab68..0000000 --- a/include/list.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * storage - * - * Copyright (c) 2012 - 2013 Samsung Electronics Co., Ltd. All rights reserved. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef __LIST_H__ -#define __LIST_H__ - -#include - -#ifdef EINA_LIST -#include -typedef Eina_List dd_list; -#define DD_LIST_PREPEND(a, b) \ - a = eina_list_prepend(a, b) -#define DD_LIST_APPEND(a, b) \ - a = eina_list_append(a, b) -#define DD_LIST_REMOVE(a, b) \ - a = eina_list_remove(a, b) -#define DD_LIST_LENGTH(a) \ - eina_list_count(a) -#define DD_LIST_NTH(a, b) \ - eina_list_nth(a, b) -#define DD_LIST_FREE_LIST(a) \ - a = eina_list_free(a) -#define DD_LIST_FOREACH(head, elem, node) \ - EINA_LIST_FOREACH(head, elem, node) -#define DD_LIST_FOREACH_SAFE(head, elem, elem_next, node) \ - EINA_LIST_FOREACH_SAFE(head, elem, elem_next, node) - -#else -#include -typedef GList dd_list; -#define DD_LIST_PREPEND(a, b) \ - a = g_list_prepend(a, (gpointer)b) -#define DD_LIST_APPEND(a, b) \ - a = g_list_append(a, (gpointer)b) -#define DD_LIST_REMOVE(a, b) \ - a = g_list_remove(a, (gpointer)b) -#define DD_LIST_LENGTH(a) \ - g_list_length(a) -#define DD_LIST_NTH(a, b) \ - g_list_nth_data(a, b) -#define DD_LIST_FREE_LIST(a) \ - g_list_free(a) -#define DD_LIST_FOREACH(head, elem, node) \ - for (elem = head, node = NULL; elem && ((node = elem->data) != NULL); elem = elem->next, node = NULL) -#define DD_LIST_FOREACH_SAFE(head, elem, elem_next, node) \ - for (elem = head, elem_next = g_list_next(elem), node = NULL; \ - elem && ((node = elem->data) != NULL); \ - elem = elem_next, elem_next = g_list_next(elem), node = NULL) - -#endif - -#endif diff --git a/packaging/libstorage.spec b/packaging/libstorage.spec index 849064d..e6d2da5 100644 --- a/packaging/libstorage.spec +++ b/packaging/libstorage.spec @@ -16,6 +16,7 @@ BuildRequires: pkgconfig(libtzplatform-config) BuildRequires: pkgconfig(mount) BuildRequires: pkgconfig(blkid) BuildRequires: pkgconfig(capi-system-info) +BuildRequires: pkgconfig(libsyscommon) %if 0%{?gcov:1} BuildRequires: lcov %endif diff --git a/src/statvfs.c b/src/statvfs.c index e7e9e56..7883276 100644 --- a/src/statvfs.c +++ b/src/statvfs.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "log.h" #include "common.h" @@ -38,21 +39,9 @@ #define STORAGE_CONF_FILE "/etc/storage/libstorage.conf" -#define MAX_LINE 128 -#define MAX_SECTION 64 -#define WHITESPACE " \t" -#define NEWLINE "\n\r" -#define COMMENT '#' - #define MATCH(a, b) (!strncmp(a, b, strlen(a))) #define SET_CONF(a, b) (a = (b > 0.0 ? b : a)) -struct parse_result { - char *section; - char *name; - char *value; -}; - struct storage_config_info { double total_size; double check_size; @@ -61,103 +50,6 @@ struct storage_config_info { static struct storage_config_info storage_info; -static inline char *trim_str(char *s) -{ - char *t; - /* left trim */ - s += strspn(s, WHITESPACE); - - /* right trim */ - for (t = strchr(s, 0); t > s; t--) - if (!strchr(WHITESPACE, t[-1])) - break; - *t = 0; - return s; -} - -static int config_parse(const char *file_name, int cb(struct parse_result *result, - void *user_data), void *user_data) -{ - FILE *f = NULL; - struct parse_result result; - /* use stack for parsing */ - char line[MAX_LINE]; - char section[MAX_SECTION]; - char *start, *end, *name, *value; - int lineno = 0, ret = 0; - - if (!file_name || !cb) { - ret = -EINVAL; - goto error; - } - - /* open conf file */ - f = fopen(file_name, "r"); - if (!f) { - _E("Failed to open file %s", file_name); //LCOV_EXCL_LINE - ret = -EIO; - goto error; - } - - /* parsing line by line */ - while (fgets(line, MAX_LINE, f) != NULL) { - lineno++; - - start = line; - start[strcspn(start, NEWLINE)] = '\0'; - start = trim_str(start); - - if (*start == COMMENT) { - continue; - } else if (*start == '[') { - /* parse section */ - end = strchr(start, ']'); - if (!end || *end != ']') { - ret = -EBADMSG; - goto error; - } - - *end = '\0'; - strncpy(section, start + 1, sizeof(section) - 1); - section[MAX_SECTION-1] = '\0'; - } else if (*start) { - /* parse name & value */ - end = strchr(start, '='); - if (!end || *end != '=') { - ret = -EBADMSG; - goto error; - } - *end = '\0'; - name = trim_str(start); - value = trim_str(end + 1); - end = strchr(value, COMMENT); - if (end && *end == COMMENT) { - *end = '\0'; - value = trim_str(value); - } - - result.section = section; - result.name = name; - result.value = value; - /* callback with parse result */ - ret = cb(&result, user_data); - if (ret < 0) { - ret = -EBADMSG; - goto error; - } - } - } - _D("Success to load %s", file_name); - fclose(f); - return 0; - -error: - if (f) - fclose(f); - _E("Failed to read %s:%d!", file_name, lineno); //LCOV_EXCL_LINE - return ret; -} - static int load_config(struct parse_result *result, void *user_data) { static int check_size = -1; diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index 731296a..a6e83c7 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -23,11 +23,13 @@ #include #include #include -#include #include #include +#include #include #include +#include +#include #include "log.h" #include "storage-external-dbus.h" @@ -51,12 +53,7 @@ struct storage_ext_callback { guint block_id; }; -typedef struct { - dbus_pending_cb func; - void *data; -} pending_call_data; - -static dd_list *changed_list; +static GList *changed_list; static void storage_ext_release_internal(storage_ext_device *dev) { @@ -80,15 +77,15 @@ void storage_ext_release_device(storage_ext_device **dev) *dev = NULL; } -void storage_ext_release_list(dd_list **list) +void storage_ext_release_list(GList **list) { storage_ext_device *dev; - dd_list *elem; + GList *elem; if (*list == NULL) return; - DD_LIST_FOREACH(*list, elem, dev) { + SYS_G_LIST_FOREACH(*list, elem, dev) { storage_ext_release_internal(dev); free(dev); } @@ -97,140 +94,7 @@ void storage_ext_release_list(dd_list **list) *list = NULL; } -static GDBusConnection *get_dbus_connection(void) -{ - GError *err = NULL; - static GDBusConnection *conn; - - if (conn) - return conn; - -#if !GLIB_CHECK_VERSION(2, 35, 0) - g_type_init(); -#endif - - conn = g_bus_get_sync(G_BUS_TYPE_SYSTEM, NULL, &err); - if (!conn) { -//LCOV_EXCL_START System Error - if (err) { - _E("fail to get dbus connection : %s", err->message); - g_clear_error(&err); - } else - _E("fail to get dbus connection"); - return NULL; -//LCOV_EXCL_STOP - } - return conn; -} - -static void _cb_pending(GDBusConnection *conn, - GAsyncResult *res, - gpointer user_data) -{ - GVariant *reply = NULL; - GError *err = NULL; - pending_call_data *data = (pending_call_data *)user_data; - - reply = g_dbus_connection_call_finish(conn, res, &err); - if (!reply || err) { - if (!err) - g_set_error(&err, G_IO_ERROR, G_IO_ERROR_FAILED, - "Error during g_dbus_connection_call"); - - if (data && data->func) - data->func(NULL, data->data, err); - goto out; - } - - if (data && data->func) - data->func(reply, data->data, err); -out: - if (err) - g_error_free(err); - if (data) - free(data); -} - -int dbus_method_async_with_reply_var(const char *dest, const char *path, - const char *iface, const char *method, GVariant *param, - dbus_pending_cb cb, int timeout, void *data) -{ - GDBusConnection *conn; - pending_call_data *pdata = NULL; - int ret = 0; - - if (!dest || !path || !iface || !method) - return -EINVAL; - - if (timeout < -1) { - _E("wrong timeout %d", timeout); - return -EINVAL; - } - - conn = get_dbus_connection(); - if (!conn) { - _E("fail to get dbus connection"); //LCOV_EXCL_LINE - return -1; - } - - if (cb) { - pdata = (pending_call_data*)malloc(sizeof(pending_call_data)); - if (!pdata) { - ret = -ENOMEM; - goto err; - } - - pdata->func = cb; - pdata->data = data; - } - - g_dbus_connection_call(conn, dest, path, iface, method, - param, NULL, G_DBUS_CALL_FLAGS_NONE, timeout, NULL, - (GAsyncReadyCallback)_cb_pending, - pdata); - - return ret; -err: - if (param) - g_variant_unref(param); - return ret; -} - -GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path, - const gchar *iface, const gchar *method, GVariant *param) -{ - GDBusConnection *conn; - GError *err = NULL; - GVariant *ret; - - if (!dest || !path || !iface || !method) - return NULL; - - conn = get_dbus_connection(); - if (!conn) { - _E("fail to get dbus connection"); //LCOV_EXCL_LINE - return NULL; - } - - ret = g_dbus_connection_call_sync(conn, - dest, path, iface, method, - param, NULL, G_DBUS_CALL_FLAGS_NONE, - -1, NULL, &err); - if (!ret) { -//LCOV_EXCL_START System Error - if (err) { - _E("dbus method sync call failed(%s)", err->message); - g_clear_error(&err); - } else - _E("g_dbus_connection_call_sync() failed"); - return NULL; -//LCOV_EXCL_STOP - } - - return ret; -} - -int storage_ext_get_list(dd_list **list) +int storage_ext_get_list(GList **list) { GVariant *result; GVariantIter *iter; @@ -240,7 +104,7 @@ int storage_ext_get_list(dd_list **list) if (!list) return -EINVAL; - result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME, + result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, STORAGE_EXT_GET_LIST, @@ -250,7 +114,11 @@ int storage_ext_get_list(dd_list **list) return -EIO; } - g_variant_get(result, "(a(issssssisibii))", &iter); + if (!g_variant_get_safe(result, "(a(issssssisibii))", &iter)) { + _E("Failed to get params from gvariant."); + g_variant_unref(result); + return -EIO; + } while (g_variant_iter_loop(iter, "(issssssisibii)", &info.type, &info.devnode, &info.syspath, @@ -281,10 +149,10 @@ int storage_ext_get_list(dd_list **list) elem->flags = info.flags; elem->storage_id = info.storage_id; - DD_LIST_APPEND(*list, elem); + SYS_G_LIST_APPEND(*list, elem); } - ret = g_list_length(*list); + ret = SYS_G_LIST_LENGTH(*list); out: if (ret < 0) @@ -303,7 +171,7 @@ int storage_ext_get_statvfs(char *path, struct statvfs_32 *buf) memset(buf, 0, sizeof(struct statvfs_32)); - result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME, + result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_STORAGE, STORAGE_EXT_IFACE_STORAGE, STORAGE_EXT_GET_STATVFS, @@ -313,11 +181,15 @@ int storage_ext_get_statvfs(char *path, struct statvfs_32 *buf) return -EIO; } - g_variant_get(result, "(ttttttttttt)", + if (!g_variant_get_safe(result, "(ttttttttttt)", &bsize, &frsize, &blocks, &bfree, &bavail, &files, &ffree, &favail, &fsid, - &flag, &namemax); + &flag, &namemax)) { + _E("Failed to get params from gvariant."); + g_variant_unref(result); + return -EIO; + } // %llu bsize, frsize, blocks, bfree, bavail, files, ffree, favail, fsid, flag, namemax buf->f_bsize = (unsigned long)bsize; @@ -344,7 +216,7 @@ int storage_ext_get_statvfs_size64(char *path, struct statvfs *buf) memset(buf, 0, sizeof(struct statvfs)); - result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME, + result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_STORAGE, STORAGE_EXT_IFACE_STORAGE, STORAGE_EXT_GET_STATVFS, @@ -354,11 +226,15 @@ int storage_ext_get_statvfs_size64(char *path, struct statvfs *buf) return -EIO; } - g_variant_get(result, "(ttttttttttt)", + if (!g_variant_get_safe(result, "(ttttttttttt)", &(buf->f_bsize), &(buf->f_frsize), &(buf->f_blocks), &(buf->f_bfree), &(buf->f_bavail), &(buf->f_files), &(buf->f_ffree), &(buf->f_favail), &(buf->f_fsid), - &(buf->f_flag), &(buf->f_namemax)); + &(buf->f_flag), &(buf->f_namemax))) { + _E("Failed to get params from gvariant."); + g_variant_unref(result); + return -EIO; + } // %lu buf->f_bsize, buf->f_frsize, buf->f_fsid, buf->f_flag, buf->f_namemax // %llu buf->f_blocks, buf->f_bfree, buf->f_bavail, buf->f_files, buf->f_ffree, buf->f_favail @@ -383,7 +259,7 @@ int storage_ext_get_storage_level(const char *path, char **level) return -EINVAL; } - result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME, + result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_STORAGE, STORAGE_EXT_IFACE_STORAGE, STORAGE_EXT_GET_STORAGE_LEVEL, @@ -393,9 +269,15 @@ int storage_ext_get_storage_level(const char *path, char **level) return -EIO; } - g_variant_get(result, "(s)", &tmp); + if (!g_variant_get_safe(result, "(s)", &tmp)) { + _E("Failed to get params from gvariant."); + g_variant_unref(result); + return -EIO; + } + *level = strdup(tmp); g_free(tmp); + g_variant_unref(result); if (*level == NULL) return -ENOMEM; @@ -407,7 +289,7 @@ int storage_ext_get_storage_level(const char *path, char **level) static void storage_ext_device_changed(GVariant *params, enum storage_ext_state state, gpointer user_data) { storage_ext_device *dev; - dd_list *elem; + GList *elem; struct storage_ext_callback *callback; int ret; @@ -418,7 +300,7 @@ static void storage_ext_device_changed(GVariant *params, enum storage_ext_state if (!dev) return; - g_variant_get(params, "(issssssisibii)", + if (!g_variant_get_safe(params, "(issssssisibii)", &dev->type, &dev->devnode, &dev->syspath, @@ -431,7 +313,8 @@ static void storage_ext_device_changed(GVariant *params, enum storage_ext_state &dev->state, &dev->primary, &dev->flags, - &dev->storage_id); + &dev->storage_id)) + return; /* Callback is called when unmount is started(DeviceBlocked signal) */ if (state == STORAGE_EXT_CHANGED && dev->state == STORAGE_EXT_UNMOUNTED) { @@ -439,7 +322,7 @@ static void storage_ext_device_changed(GVariant *params, enum storage_ext_state return; } - DD_LIST_FOREACH(changed_list, elem, callback) { + SYS_G_LIST_FOREACH(changed_list, elem, callback) { if (!callback->func) continue; ret = callback->func(dev, state, callback->data); @@ -493,15 +376,14 @@ static void storage_ext_changed(GDBusConnection *conn, int storage_ext_register_device_change(storage_ext_changed_cb func, void *data) { - GDBusConnection *conn; guint block_id = 0; struct storage_ext_callback *callback; - dd_list *elem; + GList *elem; if (!func) return -EINVAL; - DD_LIST_FOREACH(changed_list, elem, callback) { + SYS_G_LIST_FOREACH(changed_list, elem, callback) { if (callback->func != func) continue; if (callback->block_id == 0) @@ -518,22 +400,9 @@ int storage_ext_register_device_change(storage_ext_changed_cb func, void *data) //LCOV_EXCL_STOP } - conn = get_dbus_connection(); - if (!conn) { - //LCOV_EXCL_START System Error - free(callback); - _E("Failed to get dbus connection"); - return -EPERM; - //LCOV_EXCL_STOP - } - - block_id = g_dbus_connection_signal_subscribe(conn, - NULL, + block_id = subscribe_dbus_signal(NULL, NULL, STORAGE_EXT_IFACE_MANAGER, NULL, - NULL, - NULL, - G_DBUS_SIGNAL_FLAGS_NONE, storage_ext_changed, NULL, NULL); @@ -549,36 +418,27 @@ int storage_ext_register_device_change(storage_ext_changed_cb func, void *data) callback->data = data; callback->block_id = block_id; - DD_LIST_APPEND(changed_list, callback); + SYS_G_LIST_APPEND(changed_list, callback); return 0; } void storage_ext_unregister_device_change(storage_ext_changed_cb func) { - GDBusConnection *conn; struct storage_ext_callback *callback; - dd_list *elem; - dd_list *elem_n; + GList *elem; + GList *elem_n; if (!func) return; - conn = get_dbus_connection(); - if (!conn) { -//LCOV_EXCL_START System Error - _E("fail to get dbus connection"); - return; -//LCOV_EXCL_STOP - } - - DD_LIST_FOREACH_SAFE(changed_list, elem, elem_n, callback) { + SYS_G_LIST_FOREACH_SAFE(changed_list, elem, elem_n, callback) { if (callback->func != func) continue; if (callback->block_id > 0) - g_dbus_connection_signal_unsubscribe(conn, callback->block_id); + unsubscribe_dbus_signal(NULL, callback->block_id); - DD_LIST_REMOVE(changed_list, callback); + SYS_G_LIST_REMOVE(changed_list, callback); free(callback); } } @@ -586,8 +446,9 @@ void storage_ext_unregister_device_change(storage_ext_changed_cb func) int storage_ext_get_device_info(int storage_id, storage_ext_device *info) { GVariant *result; + int ret; - result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME, + result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, "GetDeviceInfo", @@ -597,25 +458,26 @@ int storage_ext_get_device_info(int storage_id, storage_ext_device *info) return -ENODEV; } - if (g_variant_check_format_string(result, "(issssssisibii)", true)) { - g_variant_get(result, "(issssssisibii)", + if (!g_variant_get_safe(result, "(issssssisibii)", &info->type, &info->devnode, &info->syspath, &info->fs_usage, &info->fs_type, &info->fs_version, &info->fs_uuid, &info->readonly, &info->mount_point, &info->state, &info->primary, - &info->flags, &info->storage_id); - } else { + &info->flags, &info->storage_id)) { _E("No storage with the storage id (%d)", storage_id); //LCOV_EXCL_LINE - return -ENODEV; + ret = -ENODEV; + goto out; } if (info->storage_id < 0) { _E("No storage with the storage id (%d)", storage_id); //LCOV_EXCL_LINE - return -ENODEV; + ret = -ENODEV; + goto out; } + ret = 0; +out: g_variant_unref(result); - - return 0; + return ret; } diff --git a/src/storage-external-dbus.h b/src/storage-external-dbus.h index 273e388..b9bcea4 100644 --- a/src/storage-external-dbus.h +++ b/src/storage-external-dbus.h @@ -23,7 +23,6 @@ #include #include #include -#include "list.h" #define STORAGE_EXT_BUS_NAME "org.tizen.system.storage" #define STORAGE_EXT_PATH_MANAGER "/Org/Tizen/System/Storage/Block/Manager" @@ -97,8 +96,8 @@ typedef int (*storage_ext_changed_cb)(storage_ext_device *dev, enum storage_ext_ int storage_ext_is_supported(void); void storage_ext_release_device(storage_ext_device **dev); -void storage_ext_release_list(dd_list **list); -int storage_ext_get_list(dd_list **list); +void storage_ext_release_list(GList **list); +int storage_ext_get_list(GList **list); int storage_ext_get_statvfs(char *path, struct statvfs_32 *buf); int storage_ext_get_statvfs_size64(char *path, struct statvfs *buf); @@ -108,12 +107,4 @@ void storage_ext_unregister_device_change(storage_ext_changed_cb func); int storage_ext_get_device_info(int storage_id, storage_ext_device *info); int storage_ext_get_storage_level(const char *path, char **level); -typedef void (*dbus_pending_cb)(GVariant *var, void *user_data, GError *err); -int dbus_method_async_with_reply_var(const char *dest, const char *path, - const char *iface, const char *method, GVariant *param, - dbus_pending_cb cb, int timeout, void *data); -/* storage-internal.c */ -GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path, - const gchar *iface, const gchar *method, GVariant *param); - #endif /* __STORAGE_EXTERNAL_DBUS_H__ */ diff --git a/src/storage-external.c b/src/storage-external.c index 3033915..e260ebc 100755 --- a/src/storage-external.c +++ b/src/storage-external.c @@ -22,9 +22,9 @@ #include #include #include +#include #include "common.h" -#include "list.h" #include "log.h" #include "storage-external-dbus.h" @@ -34,7 +34,7 @@ #define LUKS_NAME "crypto_LUKS" -static dd_list *cb_list[STORAGE_CALLBACK_MAX]; +static GList *cb_list[STORAGE_CALLBACK_MAX]; static int storage_ext_get_dev_state(storage_ext_device *dev, enum storage_ext_state blk_state, @@ -134,7 +134,7 @@ int storage_ext_foreach_device_list(storage_device_supported_cb callback, void * { int ret; bool ret_cb; - dd_list *list = NULL, *elem; + GList *list = NULL, *elem; storage_ext_device *dev; storage_state_e state; @@ -147,7 +147,7 @@ int storage_ext_foreach_device_list(storage_device_supported_cb callback, void * return ret; } - DD_LIST_FOREACH(list, elem, dev) { + SYS_G_LIST_FOREACH(list, elem, dev) { ret = storage_ext_get_dev_state(dev, STORAGE_EXT_CHANGED, &state); if (ret < 0) { _E("Failed to get storage state (devnode:%s, ret:%d)", dev->devnode, ret); //LCOV_EXCL_LINE @@ -175,7 +175,7 @@ static int storage_ext_id_changed(storage_ext_device *dev, enum storage_ext_stat { enum storage_cb_type type = (enum storage_cb_type)data; struct storage_cb_info *cb_info; - dd_list *elem; + GList *elem; storage_state_e state; int ret; @@ -191,7 +191,7 @@ static int storage_ext_id_changed(storage_ext_device *dev, enum storage_ext_stat return ret; } - DD_LIST_FOREACH(cb_list[STORAGE_CALLBACK_ID], elem, cb_info) + SYS_G_LIST_FOREACH(cb_list[STORAGE_CALLBACK_ID], elem, cb_info) cb_info->state_cb(cb_info->id, state, cb_info->user_data); return 0; @@ -201,7 +201,7 @@ static int storage_ext_type_changed(storage_ext_device *dev, enum storage_ext_st { enum storage_cb_type type = (enum storage_cb_type)data; struct storage_cb_info *cb_info; - dd_list *elem; + GList *elem; storage_state_e state; int ret; storage_dev_e strdev; @@ -241,7 +241,7 @@ static int storage_ext_type_changed(storage_ext_device *dev, enum storage_ext_st if (!strncmp(fstype, LUKS_NAME, strlen(LUKS_NAME))) storage_type = STORAGE_TYPE_EXTENDED_INTERNAL; - DD_LIST_FOREACH(cb_list[STORAGE_CALLBACK_TYPE], elem, cb_info) { + SYS_G_LIST_FOREACH(cb_list[STORAGE_CALLBACK_TYPE], elem, cb_info) { if (cb_info->type != storage_type) continue; if (cb_info->type_cb) @@ -259,13 +259,13 @@ static bool check_if_callback_exist(enum storage_cb_type type, struct storage_cb_info *info, struct storage_cb_info **cb_data) { struct storage_cb_info *cb_info; - dd_list *elem; + GList *elem; if (!info) return false; if (type == STORAGE_CALLBACK_ID) { - DD_LIST_FOREACH(cb_list[type], elem, cb_info) { + SYS_G_LIST_FOREACH(cb_list[type], elem, cb_info) { if (cb_info->id == info->id && cb_info->state_cb == info->state_cb) { goto out; @@ -274,7 +274,7 @@ static bool check_if_callback_exist(enum storage_cb_type type, } if (type == STORAGE_CALLBACK_TYPE) { - DD_LIST_FOREACH(cb_list[type], elem, cb_info) { + SYS_G_LIST_FOREACH(cb_list[type], elem, cb_info) { if (cb_info->type == info->type && cb_info->type_cb == info->type_cb) goto out; @@ -311,7 +311,7 @@ int storage_ext_register_cb(enum storage_cb_type type, struct storage_cb_info *i return -EINVAL; } - n = DD_LIST_LENGTH(cb_list[type]); + n = SYS_G_LIST_LENGTH(cb_list[type]); if (n == 0) { ret = storage_ext_register_device_change(callback, (void *)type); if (ret < 0) @@ -329,7 +329,7 @@ int storage_ext_register_cb(enum storage_cb_type type, struct storage_cb_info *i return -errno; memcpy(cb_info, info, sizeof(struct storage_cb_info)); - DD_LIST_APPEND(cb_list[type], cb_info); + SYS_G_LIST_APPEND(cb_list[type], cb_info); return 0; } @@ -362,12 +362,12 @@ int storage_ext_unregister_cb(enum storage_cb_type type, struct storage_cb_info /* remove device callback from list (local) */ if (cb_info) { - DD_LIST_REMOVE(cb_list[type], cb_info); + SYS_G_LIST_REMOVE(cb_list[type], cb_info); free(cb_info); } /* check if this callback is last element */ - n = DD_LIST_LENGTH(cb_list[type]); + n = SYS_G_LIST_LENGTH(cb_list[type]); if (n == 0) storage_ext_unregister_device_change(callback); @@ -494,7 +494,7 @@ out: int storage_ext_get_primary_mmc_path(char *path, size_t len) { - dd_list *list = NULL, *elem; + GList *list = NULL, *elem; storage_ext_device *dev; int ret; @@ -504,7 +504,7 @@ int storage_ext_get_primary_mmc_path(char *path, size_t len) return ret; } - DD_LIST_FOREACH(list, elem, dev) { + SYS_G_LIST_FOREACH(list, elem, dev) { if (dev->primary) { snprintf(path, len, "%s", dev->mount_point); ret = 0; diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index b35c4fb..83dd93e 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -23,9 +23,9 @@ #include #include #include +#include #include "common.h" -#include "list.h" #include "log.h" #include "storage-internal.h" #include "storage-external-dbus.h" @@ -174,7 +174,7 @@ API int storage_get_primary_sdcard(int *storage_id, char **path) if (!storage_ext_is_supported()) return STORAGE_ERROR_NOT_SUPPORTED; - result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME, + result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, "GetMmcPrimary", @@ -186,13 +186,16 @@ API int storage_get_primary_sdcard(int *storage_id, char **path) //LCOV_EXCL_STOP } - g_variant_get(result, "(issssssisibii)", + if (!g_variant_get_safe(result, "(issssssisibii)", NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &mount_point, NULL, NULL, - NULL, &id); + NULL, &id)) { + g_variant_unref(result); + return STORAGE_ERROR_OPERATION_FAILED; + } g_variant_unref(result); @@ -281,7 +284,7 @@ API int storage_request_mount_mmc(struct mmc_contents *mmc_data) free(path); //LCOV_EXCL_STOP - ret = dbus_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, + ret = dbus_handle_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, "Mount", @@ -350,7 +353,7 @@ API int storage_request_unmount_mmc(struct mmc_contents *mmc_data, int option) free(path); //LCOV_EXCL_STOP - ret = dbus_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, + ret = dbus_handle_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, "Unmount", @@ -424,7 +427,7 @@ API int storage_format_mmc(struct mmc_contents *mmc_data, int option) free(path); //LCOV_EXCL_STOP - ret = dbus_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, + ret = dbus_handle_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, "Format", diff --git a/src/storage.c b/src/storage.c index 6778dff..5185279 100644 --- a/src/storage.c +++ b/src/storage.c @@ -21,9 +21,9 @@ #include #include #include +#include #include "common.h" -#include "list.h" #include "log.h" #include "storage-external.h" @@ -40,9 +40,9 @@ const int tz_id[STORAGE_DIRECTORY_MAX] = { [STORAGE_DIRECTORY_OTHERS] = TZ_USER_OTHERS, }; -static dd_list *st_int_head; /* Internal storage list */ +static GList *st_int_head; /* Internal storage list */ -static dd_list *compat_cb_list; +static GList *compat_cb_list; struct compat_cb_info { storage_state_changed_cb user_cb; void *user_data; @@ -50,18 +50,18 @@ struct compat_cb_info { void add_device(const struct storage_ops *st) { - DD_LIST_APPEND(st_int_head, st); + SYS_G_LIST_APPEND(st_int_head, st); } void remove_device(const struct storage_ops *st) { - DD_LIST_REMOVE(st_int_head, st); + SYS_G_LIST_REMOVE(st_int_head, st); } API int storage_foreach_device_supported(storage_device_supported_cb callback, void *user_data) { const struct storage_ops *st; - dd_list *elem; + GList *elem; int ret; bool user = true; @@ -73,7 +73,7 @@ API int storage_foreach_device_supported(storage_device_supported_cb callback, v if (getuid() <= USER_UID_START) user = false; - DD_LIST_FOREACH(st_int_head, elem, st) { + SYS_G_LIST_FOREACH(st_int_head, elem, st) { if (user) { ret = callback(st->storage_id, st->type, st->get_state(), st->root(), user_data); @@ -100,7 +100,7 @@ API int storage_foreach_device_supported(storage_device_supported_cb callback, v API int storage_get_root_directory(int storage_id, char **path) { const struct storage_ops *st; - dd_list *elem; + GList *elem; char root[PATH_MAX]; int ret; bool extendedint; @@ -118,7 +118,7 @@ API int storage_get_root_directory(int storage_id, char **path) user = false; /* internal storage */ - DD_LIST_FOREACH(st_int_head, elem, st) { + SYS_G_LIST_FOREACH(st_int_head, elem, st) { if (st->storage_id != storage_id) continue; if (!user) { @@ -170,7 +170,7 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p char temp[PATH_MAX]; char *temp2, *end; int ret; - dd_list *elem; + GList *elem; bool found; bool extendedint; bool user = true; @@ -190,7 +190,7 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p /* internal storage */ found = false; - DD_LIST_FOREACH(st_int_head, elem, st) { + SYS_G_LIST_FOREACH(st_int_head, elem, st) { if (st->storage_id != storage_id) continue; found = true; @@ -271,7 +271,7 @@ out: API int storage_get_type(int storage_id, storage_type_e *type) { const struct storage_ops *st; - dd_list *elem; + GList *elem; char root[PATH_MAX]; int ret; bool extendedint; @@ -285,7 +285,7 @@ API int storage_get_type(int storage_id, storage_type_e *type) } /* internal storage */ - DD_LIST_FOREACH(st_int_head, elem, st) { + SYS_G_LIST_FOREACH(st_int_head, elem, st) { if (st->storage_id != storage_id) continue; *type = st->type; @@ -320,7 +320,7 @@ API int storage_get_state(int storage_id, storage_state_e *state) { const struct storage_ops *ops; storage_state_e st; - dd_list *elem; + GList *elem; int ret; if (storage_id < 0) @@ -332,7 +332,7 @@ API int storage_get_state(int storage_id, storage_state_e *state) } /* internal storage */ - DD_LIST_FOREACH(st_int_head, elem, ops) { + SYS_G_LIST_FOREACH(st_int_head, elem, ops) { if (ops->storage_id != storage_id) continue; *state = ops->get_state(); @@ -367,10 +367,10 @@ static void compat_cb(int storage_id, bool primary, int flags, void *user_data) { struct compat_cb_info* ccb_info; - dd_list *elem; + GList *elem; if (storage_id == STORAGE_TYPE_EXTERNAL && dev == STORAGE_DEV_EXT_SDCARD) - DD_LIST_FOREACH(compat_cb_list, elem, ccb_info) + SYS_G_LIST_FOREACH(compat_cb_list, elem, ccb_info) ccb_info->user_cb(storage_id, state, ccb_info->user_data); } //LCOV_EXCL_STOP @@ -380,7 +380,7 @@ API int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb ca const struct storage_ops *st; struct storage_cb_info info; int ret; - dd_list *elem; + GList *elem; struct compat_cb_info* ccb_info; static int compat_cb_init = 0; @@ -413,13 +413,13 @@ API int storage_set_state_changed_cb(int storage_id, storage_state_changed_cb ca return STORAGE_ERROR_OPERATION_FAILED; ccb_info->user_cb = callback; ccb_info->user_data = user_data; - DD_LIST_APPEND(compat_cb_list, ccb_info); + SYS_G_LIST_APPEND(compat_cb_list, ccb_info); return STORAGE_ERROR_NONE; } /* Internal storage does not support registering changed callback */ - DD_LIST_FOREACH(st_int_head, elem, st) + SYS_G_LIST_FOREACH(st_int_head, elem, st) if (st->storage_id == storage_id) return STORAGE_ERROR_NONE; @@ -447,7 +447,7 @@ API int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb const struct storage_ops *st; struct storage_cb_info info; int ret; - dd_list *elem; + GList *elem; if (storage_id < 0) return STORAGE_ERROR_INVALID_PARAMETER; @@ -464,12 +464,12 @@ API int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb return STORAGE_ERROR_NOT_SUPPORTED; } - dd_list *elem_n; + GList *elem_n; struct compat_cb_info* ccb_info; - DD_LIST_FOREACH_SAFE(compat_cb_list, elem, elem_n, ccb_info) { + SYS_G_LIST_FOREACH_SAFE(compat_cb_list, elem, elem_n, ccb_info) { if (ccb_info->user_cb == callback) { - DD_LIST_REMOVE(compat_cb_list, ccb_info); + SYS_G_LIST_REMOVE(compat_cb_list, ccb_info); free(ccb_info); return STORAGE_ERROR_NONE; } @@ -478,7 +478,7 @@ API int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb } /* Internal storage does not support registering changed callback */ - DD_LIST_FOREACH(st_int_head, elem, st) + SYS_G_LIST_FOREACH(st_int_head, elem, st) if (st->storage_id == storage_id) return STORAGE_ERROR_NONE; @@ -505,7 +505,7 @@ API int storage_get_total_space(int storage_id, unsigned long long *bytes) const struct storage_ops *st; unsigned long long total; int ret; - dd_list *elem; + GList *elem; if (storage_id < 0) return STORAGE_ERROR_INVALID_PARAMETER; @@ -516,7 +516,7 @@ API int storage_get_total_space(int storage_id, unsigned long long *bytes) } /* internal storage */ - DD_LIST_FOREACH(st_int_head, elem, st) { + SYS_G_LIST_FOREACH(st_int_head, elem, st) { if (st->storage_id != storage_id) continue; ret = st->get_space(&total, NULL); @@ -551,7 +551,7 @@ API int storage_get_available_space(int storage_id, unsigned long long *bytes) const struct storage_ops *st; unsigned long long avail; int ret; - dd_list *elem; + GList *elem; if (storage_id < 0) return STORAGE_ERROR_INVALID_PARAMETER; @@ -562,7 +562,7 @@ API int storage_get_available_space(int storage_id, unsigned long long *bytes) } /* internal storage */ - DD_LIST_FOREACH(st_int_head, elem, st) { + SYS_G_LIST_FOREACH(st_int_head, elem, st) { if (st->storage_id != storage_id) continue; ret = st->get_space(NULL, &avail); -- 2.7.4 From 999645b53cd76fefa54e24a73c4239183ecbb81f Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Tue, 9 Mar 2021 15:26:55 +0900 Subject: [PATCH 10/16] Apply libsyscommon gdbus api improvement on error handling Change-Id: I50e592ff81431ff8580c9c153d865e3f0144c616 Signed-off-by: taemin.yeom --- src/storage-external-dbus.c | 38 +++++++++++++++++++++++--------------- src/storage-inhouse.c | 7 ++++--- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index a6e83c7..ee3016e 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -104,12 +104,13 @@ int storage_ext_get_list(GList **list) if (!list) return -EINVAL; - result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, + ret = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, STORAGE_EXT_GET_LIST, - g_variant_new("(s)", "all")); - if (!result) { + g_variant_new("(s)", "all"), + &result); + if (ret < 0) { _E("Failed to get storage_ext device info"); //LCOV_EXCL_LINE return -EIO; } @@ -165,18 +166,20 @@ out: int storage_ext_get_statvfs(char *path, struct statvfs_32 *buf) { GVariant *result; + int ret; guint64 bsize, frsize, blocks, bfree, bavail, files, ffree, favail, fsid, flag, namemax; assert(buf); memset(buf, 0, sizeof(struct statvfs_32)); - result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, + ret = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_STORAGE, STORAGE_EXT_IFACE_STORAGE, STORAGE_EXT_GET_STATVFS, - g_variant_new("(s)", path)); - if (!result) { + g_variant_new("(s)", path), + &result); + if (ret < 0) { _E("Failed to get storage_ext device info"); //LCOV_EXCL_LINE return -EIO; } @@ -211,17 +214,19 @@ int storage_ext_get_statvfs(char *path, struct statvfs_32 *buf) int storage_ext_get_statvfs_size64(char *path, struct statvfs *buf) { GVariant *result; + int ret; assert(buf); memset(buf, 0, sizeof(struct statvfs)); - result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, + ret = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_STORAGE, STORAGE_EXT_IFACE_STORAGE, STORAGE_EXT_GET_STATVFS, - g_variant_new("(s)", path)); - if (!result) { + g_variant_new("(s)", path), + &result); + if (ret < 0) { _E("Failed to get storage_ext device info"); //LCOV_EXCL_LINE return -EIO; } @@ -245,6 +250,7 @@ int storage_ext_get_statvfs_size64(char *path, struct statvfs *buf) int storage_ext_get_storage_level(const char *path, char **level) { GVariant *result; + int ret; char *tmp; enum tzplatform_variable id; @@ -259,12 +265,13 @@ int storage_ext_get_storage_level(const char *path, char **level) return -EINVAL; } - result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, + ret = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_STORAGE, STORAGE_EXT_IFACE_STORAGE, STORAGE_EXT_GET_STORAGE_LEVEL, - g_variant_new("(i)", id)); - if (!result) { + g_variant_new("(i)", id), + &result); + if (ret < 0) { _E("Failed to get %d level", id); return -EIO; } @@ -448,12 +455,13 @@ int storage_ext_get_device_info(int storage_id, storage_ext_device *info) GVariant *result; int ret; - result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, + ret = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, "GetDeviceInfo", - g_variant_new("(i)", storage_id)); - if (!result) { + g_variant_new("(i)", storage_id), + &result); + if (ret < 0) { _E("There is no storage with the storage id (%d)", storage_id); //LCOV_EXCL_LINE return -ENODEV; } diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index 83dd93e..fddb656 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -174,12 +174,13 @@ API int storage_get_primary_sdcard(int *storage_id, char **path) if (!storage_ext_is_supported()) return STORAGE_ERROR_NOT_SUPPORTED; - result = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, + ret = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, "GetMmcPrimary", - NULL); - if (!result) { + NULL, + &result); + if (ret < 0) { //LCOV_EXCL_START System Error _E("Failed to get primary sdcard partition"); //LCOV_EXCL_LINE return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE -- 2.7.4 From 67d0a89693635811c506bedb7409b99aea197191 Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Fri, 12 Mar 2021 16:56:25 +0900 Subject: [PATCH 11/16] Improve variable naming style Change-Id: Ic97f7e14016d60405fb55dffaf0d62ab411ec849 Signed-off-by: taemin.yeom --- src/statvfs.c | 56 +++++++++++----------- src/storage-common.c | 8 ++-- src/storage-external-dbus.c | 95 +++++++++++++++++++------------------ src/storage-external.c | 30 ++++++------ src/storage-inhouse.c | 108 +++++++++++++++++++++--------------------- src/storage-internal.c | 8 ++-- src/storage.c | 112 ++++++++++++++++++++++---------------------- 7 files changed, 208 insertions(+), 209 deletions(-) diff --git a/src/statvfs.c b/src/statvfs.c index 7883276..0e8bac6 100644 --- a/src/statvfs.c +++ b/src/statvfs.c @@ -80,22 +80,22 @@ static int load_config(struct parse_result *result, void *user_data) static void storage_config_load(struct storage_config_info *info) { - int ret; + int ret_val; - ret = config_parse(STORAGE_CONF_FILE, load_config, info); - if (ret < 0) - _E("Failed to load %s, %d Use default value!", STORAGE_CONF_FILE, ret); //LCOV_EXCL_LINE + ret_val = config_parse(STORAGE_CONF_FILE, load_config, info); + if (ret_val < 0) + _E("Failed to load %s, %d Use default value!", STORAGE_CONF_FILE, ret_val); //LCOV_EXCL_LINE } static int get_memory_size(const char *path, struct statvfs_32 *buf) { struct statvfs s; - int ret; + int ret_val; assert(buf); - ret = statvfs(path, &s); - if (ret) + ret_val = statvfs(path, &s); + if (ret_val) return -errno; //LCOV_EXCL_LINE System Error memset(buf, 0, sizeof(struct statvfs_32)); @@ -120,16 +120,16 @@ API int storage_get_internal_memory_size(struct statvfs *buf) { struct statvfs_32 temp; static unsigned long reserved = 0; - int ret; + int ret_val; if (!buf) { _E("input param error"); return STORAGE_ERROR_INVALID_PARAMETER; } - ret = get_memory_size(tzplatform_getenv(TZ_SYS_USER), &temp); - if (ret || temp.f_bsize == 0) { - _E("fail to get memory size %d", ret); //LCOV_EXCL_LINE + ret_val = get_memory_size(tzplatform_getenv(TZ_SYS_USER), &temp); + if (ret_val || temp.f_bsize == 0) { + _E("fail to get memory size %d", ret_val); //LCOV_EXCL_LINE return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE } @@ -154,15 +154,15 @@ API int storage_get_internal_memory_size(struct statvfs *buf) API int storage_get_internal_memory_size64(struct statvfs *buf) { static unsigned long reserved = 0; - int ret; + int ret_val; if (!buf) { _E("input param error"); //LCOV_EXCL_LINE return STORAGE_ERROR_INVALID_PARAMETER; } - ret = statvfs(tzplatform_getenv(TZ_SYS_USER), buf); - if (ret) { + ret_val = statvfs(tzplatform_getenv(TZ_SYS_USER), buf); + if (ret_val) { _E("fail to get memory size"); //LCOV_EXCL_LINE return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE } @@ -211,7 +211,7 @@ static int get_external_path(char *path, size_t len) int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf) { struct statvfs_32 temp; - int ret; + int ret_val; char ext_path[32]; _D("storage_get_external_memory_size"); @@ -227,11 +227,11 @@ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf) _D("Block module is not enabled"); return STORAGE_ERROR_NOT_SUPPORTED; } - ret = get_external_path(ext_path, sizeof(ext_path)); - if (ret == -ENODEV) + ret_val = get_external_path(ext_path, sizeof(ext_path)); + if (ret_val == -ENODEV) goto out_nodev; - if (ret < 0) { - _E("Failed to get external path(%d)", ret); //LCOV_EXCL_LINE + if (ret_val < 0) { + _E("Failed to get external path(%d)", ret_val); //LCOV_EXCL_LINE return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE } } @@ -239,8 +239,8 @@ int storage_get_external_memory_size_with_path(char *path, struct statvfs *buf) if (!mount_check((const char *)ext_path)) goto out_nodev; - ret = storage_ext_get_statvfs(ext_path, &temp); - if (ret != 0) { + ret_val = storage_ext_get_statvfs(ext_path, &temp); + if (ret_val != 0) { _E("fail to get memory size"); //LCOV_EXCL_LINE return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE } @@ -256,7 +256,7 @@ out_nodev: /* This api is intended for binaries built with __USE_FILE_OFFSET64(_FILE_OFFSET_BITS=64) */ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf) { - int ret; + int ret_val; char ext_path[32]; _D("storage_get_external_memory_size64"); @@ -272,11 +272,11 @@ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf _D("Block module is not enabled"); return STORAGE_ERROR_NOT_SUPPORTED; } - ret = get_external_path(ext_path, sizeof(ext_path)); - if (ret == -ENODEV) + ret_val = get_external_path(ext_path, sizeof(ext_path)); + if (ret_val == -ENODEV) goto out_nodev; - if (ret < 0) { - _E("Failed to get external path(%d)", ret); + if (ret_val < 0) { + _E("Failed to get external path(%d)", ret_val); return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE } } @@ -284,8 +284,8 @@ int storage_get_external_memory_size64_with_path(char *path, struct statvfs *buf if (!mount_check((const char *)ext_path)) goto out_nodev; - ret = storage_ext_get_statvfs_size64(ext_path, buf); - if (ret != 0) { + ret_val = storage_ext_get_statvfs_size64(ext_path, buf); + if (ret_val != 0) { //LCOV_EXCL_START System Error _E("fail to get memory size"); return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE diff --git a/src/storage-common.c b/src/storage-common.c index cc6ea2e..fdd3825 100644 --- a/src/storage-common.c +++ b/src/storage-common.c @@ -57,16 +57,16 @@ int is_compat_bind_mount(void) int storage_ext_is_supported(void) { static int support = -1; - int ret; + int ret_val; bool ext_avail; if (support >= 0) return support; - ret = system_info_get_platform_bool(EXTERNAL_FEATURE, &ext_avail); - if (ret < 0) + ret_val = system_info_get_platform_bool(EXTERNAL_FEATURE, &ext_avail); + if (ret_val < 0) support = 0; - else if (ret == 0 && !ext_avail) + else if (ret_val == 0 && !ext_avail) support = 0; else support = 1; diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index ee3016e..1b71d56 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -96,28 +96,28 @@ void storage_ext_release_list(GList **list) int storage_ext_get_list(GList **list) { - GVariant *result; + GVariant *reply; GVariantIter *iter; storage_ext_device *elem, info; - int ret; + int ret, ret_dbus; if (!list) return -EINVAL; - ret = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, + ret_dbus = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, STORAGE_EXT_GET_LIST, g_variant_new("(s)", "all"), - &result); - if (ret < 0) { + &reply); + if (ret_dbus < 0) { _E("Failed to get storage_ext device info"); //LCOV_EXCL_LINE return -EIO; } - if (!g_variant_get_safe(result, "(a(issssssisibii))", &iter)) { + if (!g_variant_get_safe(reply, "(a(issssssisibii))", &iter)) { _E("Failed to get params from gvariant."); - g_variant_unref(result); + g_variant_unref(reply); return -EIO; } @@ -159,38 +159,38 @@ out: if (ret < 0) storage_ext_release_list(list); //LCOV_EXCL_LINE System Error g_variant_iter_free(iter); - g_variant_unref(result); + g_variant_unref(reply); return ret; } int storage_ext_get_statvfs(char *path, struct statvfs_32 *buf) { - GVariant *result; - int ret; + GVariant *reply; + int ret_dbus; guint64 bsize, frsize, blocks, bfree, bavail, files, ffree, favail, fsid, flag, namemax; assert(buf); memset(buf, 0, sizeof(struct statvfs_32)); - ret = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, + ret_dbus = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_STORAGE, STORAGE_EXT_IFACE_STORAGE, STORAGE_EXT_GET_STATVFS, g_variant_new("(s)", path), - &result); - if (ret < 0) { + &reply); + if (ret_dbus < 0) { _E("Failed to get storage_ext device info"); //LCOV_EXCL_LINE return -EIO; } - if (!g_variant_get_safe(result, "(ttttttttttt)", + if (!g_variant_get_safe(reply, "(ttttttttttt)", &bsize, &frsize, &blocks, &bfree, &bavail, &files, &ffree, &favail, &fsid, &flag, &namemax)) { _E("Failed to get params from gvariant."); - g_variant_unref(result); + g_variant_unref(reply); return -EIO; } // %llu bsize, frsize, blocks, bfree, bavail, files, ffree, favail, fsid, flag, namemax @@ -213,31 +213,31 @@ int storage_ext_get_statvfs(char *path, struct statvfs_32 *buf) int storage_ext_get_statvfs_size64(char *path, struct statvfs *buf) { - GVariant *result; - int ret; + GVariant *reply; + int ret_dbus; assert(buf); memset(buf, 0, sizeof(struct statvfs)); - ret = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, + ret_dbus = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_STORAGE, STORAGE_EXT_IFACE_STORAGE, STORAGE_EXT_GET_STATVFS, g_variant_new("(s)", path), - &result); - if (ret < 0) { + &reply); + if (ret_dbus < 0) { _E("Failed to get storage_ext device info"); //LCOV_EXCL_LINE return -EIO; } - if (!g_variant_get_safe(result, "(ttttttttttt)", + if (!g_variant_get_safe(reply, "(ttttttttttt)", &(buf->f_bsize), &(buf->f_frsize), &(buf->f_blocks), &(buf->f_bfree), &(buf->f_bavail), &(buf->f_files), &(buf->f_ffree), &(buf->f_favail), &(buf->f_fsid), &(buf->f_flag), &(buf->f_namemax))) { _E("Failed to get params from gvariant."); - g_variant_unref(result); + g_variant_unref(reply); return -EIO; } @@ -249,9 +249,9 @@ int storage_ext_get_statvfs_size64(char *path, struct statvfs *buf) int storage_ext_get_storage_level(const char *path, char **level) { - GVariant *result; - int ret; - char *tmp; + GVariant *reply; + int ret_dbus; + char *reply_val; enum tzplatform_variable id; if (!strcmp(path, tzplatform_getenv(TZ_SYS_USER))) @@ -265,26 +265,26 @@ int storage_ext_get_storage_level(const char *path, char **level) return -EINVAL; } - ret = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, + ret_dbus = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_STORAGE, STORAGE_EXT_IFACE_STORAGE, STORAGE_EXT_GET_STORAGE_LEVEL, g_variant_new("(i)", id), - &result); - if (ret < 0) { + &reply); + if (ret_dbus < 0) { _E("Failed to get %d level", id); return -EIO; } - if (!g_variant_get_safe(result, "(s)", &tmp)) { + if (!g_variant_get_safe(reply, "(s)", &reply_val)) { _E("Failed to get params from gvariant."); - g_variant_unref(result); + g_variant_unref(reply); return -EIO; } - *level = strdup(tmp); - g_free(tmp); - g_variant_unref(result); + *level = strdup(reply_val); + g_free(reply_val); + g_variant_unref(reply); if (*level == NULL) return -ENOMEM; @@ -298,7 +298,7 @@ static void storage_ext_device_changed(GVariant *params, enum storage_ext_state storage_ext_device *dev; GList *elem; struct storage_ext_callback *callback; - int ret; + int ret_val; if (!params) return; @@ -332,9 +332,9 @@ static void storage_ext_device_changed(GVariant *params, enum storage_ext_state SYS_G_LIST_FOREACH(changed_list, elem, callback) { if (!callback->func) continue; - ret = callback->func(dev, state, callback->data); - if (ret < 0) - _E("Failed to call callback for devnode(%s, %d)", dev->devnode, ret); + ret_val = callback->func(dev, state, callback->data); + if (ret_val < 0) + _E("Failed to call callback for devnode(%s, %d)", dev->devnode, ret_val); } storage_ext_release_device(&dev); @@ -452,21 +452,21 @@ void storage_ext_unregister_device_change(storage_ext_changed_cb func) int storage_ext_get_device_info(int storage_id, storage_ext_device *info) { - GVariant *result; - int ret; + GVariant *reply; + int ret_dbus; - ret = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, + ret_dbus = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, "GetDeviceInfo", g_variant_new("(i)", storage_id), - &result); - if (ret < 0) { + &reply); + if (ret_dbus < 0) { _E("There is no storage with the storage id (%d)", storage_id); //LCOV_EXCL_LINE return -ENODEV; } - if (!g_variant_get_safe(result, "(issssssisibii)", + if (!g_variant_get_safe(reply, "(issssssisibii)", &info->type, &info->devnode, &info->syspath, &info->fs_usage, &info->fs_type, &info->fs_version, &info->fs_uuid, @@ -474,18 +474,17 @@ int storage_ext_get_device_info(int storage_id, storage_ext_device *info) &info->state, &info->primary, &info->flags, &info->storage_id)) { _E("No storage with the storage id (%d)", storage_id); //LCOV_EXCL_LINE - ret = -ENODEV; + ret_dbus = -ENODEV; goto out; } if (info->storage_id < 0) { _E("No storage with the storage id (%d)", storage_id); //LCOV_EXCL_LINE - ret = -ENODEV; + ret_dbus = -ENODEV; goto out; } - ret = 0; out: - g_variant_unref(result); - return ret; + g_variant_unref(reply); + return 0; } diff --git a/src/storage-external.c b/src/storage-external.c index e260ebc..3ffcf4a 100755 --- a/src/storage-external.c +++ b/src/storage-external.c @@ -132,7 +132,7 @@ out: int storage_ext_foreach_device_list(storage_device_supported_cb callback, void *user_data) { - int ret; + int ret_val; bool ret_cb; GList *list = NULL, *elem; storage_ext_device *dev; @@ -141,16 +141,16 @@ int storage_ext_foreach_device_list(storage_device_supported_cb callback, void * if (!callback) return -EINVAL; - ret = storage_ext_get_list(&list); - if (ret < 0) { + ret_val = storage_ext_get_list(&list); + if (ret_val < 0) { _E("Failed to get external storage list from deviced (%d)", errno); //LCOV_EXCL_LINE - return ret; + return ret_val; } SYS_G_LIST_FOREACH(list, elem, dev) { - ret = storage_ext_get_dev_state(dev, STORAGE_EXT_CHANGED, &state); - if (ret < 0) { - _E("Failed to get storage state (devnode:%s, ret:%d)", dev->devnode, ret); //LCOV_EXCL_LINE + ret_val = storage_ext_get_dev_state(dev, STORAGE_EXT_CHANGED, &state); + if (ret_val < 0) { + _E("Failed to get storage state (devnode:%s, ret_val:%d)", dev->devnode, ret_val); //LCOV_EXCL_LINE continue; } @@ -203,7 +203,7 @@ static int storage_ext_type_changed(storage_ext_device *dev, enum storage_ext_st struct storage_cb_info *cb_info; GList *elem; storage_state_e state; - int ret; + int ret_val; storage_dev_e strdev; storage_type_e storage_type; const char *fstype, *fsuuid, *mountpath; @@ -214,10 +214,10 @@ static int storage_ext_type_changed(storage_ext_device *dev, enum storage_ext_st if (type != STORAGE_CALLBACK_TYPE) return -EINVAL; - ret = storage_ext_get_dev_state(dev, blk_state, &state); - if (ret < 0) { - _E("Failed to get storage state (devnode:%s, ret:%d)", dev->devnode, ret); - return ret; + ret_val = storage_ext_get_dev_state(dev, blk_state, &state); + if (ret_val < 0) { + _E("Failed to get storage state (devnode:%s, ret_val:%d)", dev->devnode, ret_val); + return ret_val; } if (dev->type == STORAGE_EXT_SCSI) { @@ -293,7 +293,7 @@ out: int storage_ext_register_cb(enum storage_cb_type type, struct storage_cb_info *info) { struct storage_cb_info *cb_info; - int n, ret; + int n, ret_val; storage_ext_changed_cb callback; if (!info) @@ -313,8 +313,8 @@ int storage_ext_register_cb(enum storage_cb_type type, struct storage_cb_info *i n = SYS_G_LIST_LENGTH(cb_list[type]); if (n == 0) { - ret = storage_ext_register_device_change(callback, (void *)type); - if (ret < 0) + ret_val = storage_ext_register_device_change(callback, (void *)type); + if (ret_val < 0) return -EPERM; } diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index fddb656..c2d5d1b 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -163,10 +163,10 @@ API int storage_get_origin_internal_path(const char* compat, int len, char* orig API int storage_get_primary_sdcard(int *storage_id, char **path) { - GVariant *result; - int ret; - char *mount_point = NULL; - int id; + GVariant *reply; + int ret, ret_dbus; + char *reply_mount_point = NULL; + int reply_id; if (!storage_id || !path) return STORAGE_ERROR_INVALID_PARAMETER; @@ -174,65 +174,65 @@ API int storage_get_primary_sdcard(int *storage_id, char **path) if (!storage_ext_is_supported()) return STORAGE_ERROR_NOT_SUPPORTED; - ret = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, + ret_dbus = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, "GetMmcPrimary", NULL, - &result); - if (ret < 0) { + &reply); + if (ret_dbus < 0) { //LCOV_EXCL_START System Error _E("Failed to get primary sdcard partition"); //LCOV_EXCL_LINE return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE //LCOV_EXCL_STOP } - if (!g_variant_get_safe(result, "(issssssisibii)", + if (!g_variant_get_safe(reply, "(issssssisibii)", NULL, NULL, NULL, NULL, NULL, NULL, NULL, - NULL, &mount_point, + NULL, &reply_mount_point, NULL, NULL, - NULL, &id)) { - g_variant_unref(result); + NULL, &reply_id)) { + g_variant_unref(reply); return STORAGE_ERROR_OPERATION_FAILED; } - g_variant_unref(result); + g_variant_unref(reply); - if (id < 0) { + if (reply_id < 0) { ret = STORAGE_ERROR_NO_DEVICE; goto out; } - *path = strdup(mount_point); + *path = strdup(reply_mount_point); if (*path == NULL) { ret = STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE System Error goto out; } - *storage_id = id; + *storage_id = reply_id; ret = STORAGE_ERROR_NONE; out: - g_free(mount_point); + g_free(reply_mount_point); return ret; } API int storage_get_storage_level(const char *path, char **level) { - int ret; + int ret_level; if (!level || !path) return STORAGE_ERROR_INVALID_PARAMETER; - ret = storage_ext_get_storage_level(path, level); - if (ret == -ENOMEM) + ret_level = storage_ext_get_storage_level(path, level); + if (ret_level == -ENOMEM) return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE System Error - else if (ret == -EINVAL) + else if (ret_level == -EINVAL) return STORAGE_ERROR_INVALID_PARAMETER; - else if (ret < 0) + else if (ret_level < 0) return STORAGE_ERROR_OPERATION_FAILED; return STORAGE_ERROR_NONE; @@ -268,7 +268,7 @@ API int storage_request_mount_mmc(struct mmc_contents *mmc_data) void (*mount_cb)(GVariant *, void *, GError *) = NULL; void *data = NULL; char *path; - int ret; + int ret_val; int id; if (mmc_data && mmc_data->mmc_cb) { @@ -277,15 +277,15 @@ API int storage_request_mount_mmc(struct mmc_contents *mmc_data) data = mmc_data; } - ret = storage_get_primary_sdcard(&id, &path); - if (ret != STORAGE_ERROR_NONE) - return ret; + ret_val = storage_get_primary_sdcard(&id, &path); + if (ret_val != STORAGE_ERROR_NONE) + return ret_val; //LCOV_EXCL_START System Error if (path) free(path); //LCOV_EXCL_STOP - ret = dbus_handle_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, + ret_val = dbus_handle_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, "Mount", @@ -294,11 +294,11 @@ API int storage_request_mount_mmc(struct mmc_contents *mmc_data) -1, data); - _I("Mount Request %s", ret == 0 ? "Success" : "Failed"); + _I("Mount Request %s", ret_val == 0 ? "Success" : "Failed"); - if (ret == -ENOMEM) + if (ret_val == -ENOMEM) return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE System Error - if (ret < 0) + if (ret_val < 0) return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE return STORAGE_ERROR_NONE; @@ -334,7 +334,7 @@ API int storage_request_unmount_mmc(struct mmc_contents *mmc_data, int option) void (*unmount_cb)(GVariant *, void *, GError *) = NULL; void *data = NULL; char *path; - int ret; + int ret_val; int id; if (option < 0 || option > 1) @@ -346,15 +346,15 @@ API int storage_request_unmount_mmc(struct mmc_contents *mmc_data, int option) data = mmc_data; } - ret = storage_get_primary_sdcard(&id, &path); - if (ret != STORAGE_ERROR_NONE) - return ret; + ret_val = storage_get_primary_sdcard(&id, &path); + if (ret_val != STORAGE_ERROR_NONE) + return ret_val; //LCOV_EXCL_START System Error if (path) free(path); //LCOV_EXCL_STOP - ret = dbus_handle_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, + ret_val = dbus_handle_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, "Unmount", @@ -363,11 +363,11 @@ API int storage_request_unmount_mmc(struct mmc_contents *mmc_data, int option) -1, data); - _I("Unmount Request %s", ret == 0 ? "Success" : "Failed"); + _I("Unmount Request %s", ret_val == 0 ? "Success" : "Failed"); - if (ret == -ENOMEM) + if (ret_val == -ENOMEM) return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE System Error - if (ret < 0) + if (ret_val < 0) return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE return STORAGE_ERROR_NONE; @@ -408,7 +408,7 @@ API int storage_format_mmc(struct mmc_contents *mmc_data, int option) void (*format_cb)(GVariant *, void *, GError *) = NULL; void *data = NULL; char *path; - int ret; + int ret_val; int id; if (option < 0 || option > 1) @@ -420,15 +420,15 @@ API int storage_format_mmc(struct mmc_contents *mmc_data, int option) data = mmc_data; } - ret = storage_get_primary_sdcard(&id, &path); - if (ret != STORAGE_ERROR_NONE) - return ret; + ret_val = storage_get_primary_sdcard(&id, &path); + if (ret_val != STORAGE_ERROR_NONE) + return ret_val; //LCOV_EXCL_START System Error if (path) free(path); //LCOV_EXCL_STOP - ret = dbus_handle_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, + ret_val = dbus_handle_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, "Format", @@ -437,11 +437,11 @@ API int storage_format_mmc(struct mmc_contents *mmc_data, int option) FORMAT_TIMEOUT, data); - _I("Format Request %s", ret == 0 ? "Success" : "Failed"); + _I("Format Request %s", ret_val == 0 ? "Success" : "Failed"); - if (ret == -ENOMEM) + if (ret_val == -ENOMEM) return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE System Error - if (ret < 0) + if (ret_val < 0) return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE return STORAGE_ERROR_NONE; @@ -452,21 +452,21 @@ API int storage_is_mounted_opt_usr(storage_part_mount_e *mounted) blkid_cache cache = NULL; blkid_dev_iterate iter; blkid_dev dev; - int ret; + int ret_val; bool found = false; if (!mounted) return STORAGE_ERROR_INVALID_PARAMETER; - ret = blkid_get_cache(&cache, NULL); - if (ret < 0) { + ret_val = blkid_get_cache(&cache, NULL); + if (ret_val < 0) { _E("Failed to get cache"); //LCOV_EXCL_LINE *mounted = STORAGE_PART_ERROR; //LCOV_EXCL_LINE return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE } - ret = blkid_probe_all(cache); - if (ret < 0) { + ret_val = blkid_probe_all(cache); + if (ret_val < 0) { _E("Failed to probe all block devices"); //LCOV_EXCL_LINE *mounted = STORAGE_PART_ERROR; //LCOV_EXCL_LINE return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE @@ -479,7 +479,7 @@ API int storage_is_mounted_opt_usr(storage_part_mount_e *mounted) return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE } - ret = blkid_dev_set_search(iter, "LABEL", USER_PARTITION); + ret_val = blkid_dev_set_search(iter, "LABEL", USER_PARTITION); if (blkid_dev_next(iter, &dev) == 0) { dev = blkid_verify(cache, dev); if (dev) { @@ -497,7 +497,7 @@ API int storage_is_mounted_opt_usr(storage_part_mount_e *mounted) return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE } - ret = blkid_dev_set_search(iter, "PARTLABEL", USER_PARTITION); + ret_val = blkid_dev_set_search(iter, "PARTLABEL", USER_PARTITION); if (blkid_dev_next(iter, &dev) == 0) { dev = blkid_verify(cache, dev); if (dev) { @@ -511,8 +511,8 @@ API int storage_is_mounted_opt_usr(storage_part_mount_e *mounted) blkid_put_cache(cache); if (found) { - ret = mount_check(tzplatform_getenv(TZ_SYS_USER)); - if (ret) + ret_val = mount_check(tzplatform_getenv(TZ_SYS_USER)); + if (ret_val) *mounted = STORAGE_PART_MOUNTED; else *mounted = STORAGE_PART_NOT_MOUNTED; diff --git a/src/storage-internal.c b/src/storage-internal.c index 2f8a796..e0e565d 100755 --- a/src/storage-internal.c +++ b/src/storage-internal.c @@ -43,14 +43,14 @@ static int internal_get_state(void) static int internal_get_space(unsigned long long *total, unsigned long long *available) { struct statvfs s; - int ret; + int ret_val; #ifdef __USE_FILE_OFFSET64 - ret = storage_get_internal_memory_size64(&s); + ret_val = storage_get_internal_memory_size64(&s); #else - ret = storage_get_internal_memory_size(&s); + ret_val = storage_get_internal_memory_size(&s); #endif - if (ret < 0) + if (ret_val < 0) return -EPERM; if (total) diff --git a/src/storage.c b/src/storage.c index 5185279..c5e7a6f 100644 --- a/src/storage.c +++ b/src/storage.c @@ -62,7 +62,7 @@ API int storage_foreach_device_supported(storage_device_supported_cb callback, v { const struct storage_ops *st; GList *elem; - int ret; + int ret_val; bool user = true; if (!callback) { @@ -75,10 +75,10 @@ API int storage_foreach_device_supported(storage_device_supported_cb callback, v SYS_G_LIST_FOREACH(st_int_head, elem, st) { if (user) { - ret = callback(st->storage_id, st->type, st->get_state(), + ret_val = callback(st->storage_id, st->type, st->get_state(), st->root(), user_data); /* if the return value is false, will be stop to iterate */ - if (!ret) + if (!ret_val) break; } } @@ -88,9 +88,9 @@ API int storage_foreach_device_supported(storage_device_supported_cb callback, v return STORAGE_ERROR_NONE; } - ret = storage_ext_foreach_device_list(callback, user_data); - if (ret < 0) { - _E("Failed to iterate external devices (%d)", ret); //LCOV_EXCL_LINE + ret_val = storage_ext_foreach_device_list(callback, user_data); + if (ret_val < 0) { + _E("Failed to iterate external devices (%d)", ret_val); //LCOV_EXCL_LINE return STORAGE_ERROR_OPERATION_FAILED; } @@ -102,7 +102,7 @@ API int storage_get_root_directory(int storage_id, char **path) const struct storage_ops *st; GList *elem; char root[PATH_MAX]; - int ret; + int ret_val; bool extendedint; bool user = true; @@ -143,12 +143,12 @@ API int storage_get_root_directory(int storage_id, char **path) return STORAGE_ERROR_NOT_SUPPORTED; } - ret = storage_ext_get_root(storage_id, root, sizeof(root), &extendedint); - if (ret < 0) { - _E("Failed to get root path of external storage(%d, %d", storage_id, ret); //LCOV_EXCL_LINE - if (ret == -ENODEV || ret == -EINVAL) + ret_val = storage_ext_get_root(storage_id, root, sizeof(root), &extendedint); + if (ret_val < 0) { + _E("Failed to get root path of external storage(%d, %d", storage_id, ret_val); //LCOV_EXCL_LINE + if (ret_val == -ENODEV || ret_val == -EINVAL) return STORAGE_ERROR_INVALID_PARAMETER; - else if (ret == -ENOMEM) + else if (ret_val == -ENOMEM) return STORAGE_ERROR_OUT_OF_MEMORY; else return STORAGE_ERROR_OPERATION_FAILED; @@ -169,7 +169,7 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p char root[PATH_MAX]; char temp[PATH_MAX]; char *temp2, *end; - int ret; + int ret_val; GList *elem; bool found; bool extendedint; @@ -219,8 +219,8 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p snprintf(temp, PATH_MAX, "%s", temp2); free(temp2); } else { - if ((ret = snprintf(temp, PATH_MAX, "%s/%s", root, dir_path[type])) > PATH_MAX - 1) { - _E("Path is longer than buffer. Need %d size of buffer.", ret + 1); + if ((ret_val = snprintf(temp, PATH_MAX, "%s/%s", root, dir_path[type])) > PATH_MAX - 1) { + _E("Path is longer than buffer. Need %d size of buffer.", ret_val + 1); return STORAGE_ERROR_OUT_OF_MEMORY; } } @@ -239,12 +239,12 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p return STORAGE_ERROR_INVALID_PARAMETER; } - ret = storage_ext_get_root(storage_id, root, sizeof(root), &extendedint); - if (ret < 0) { - _E("Failed to get root dir for external storage(id:%d, ret:%d)", storage_id, ret); //LCOV_EXCL_LINE - if (ret == -ENODEV || ret == -EINVAL) + ret_val = storage_ext_get_root(storage_id, root, sizeof(root), &extendedint); + if (ret_val < 0) { + _E("Failed to get root dir for external storage(id:%d, ret:%d)", storage_id, ret_val); //LCOV_EXCL_LINE + if (ret_val == -ENODEV || ret_val == -EINVAL) return STORAGE_ERROR_INVALID_PARAMETER; - else if (ret == -ENOMEM) + else if (ret_val == -ENOMEM) return STORAGE_ERROR_OUT_OF_MEMORY; else return STORAGE_ERROR_OPERATION_FAILED; @@ -253,8 +253,8 @@ API int storage_get_directory(int storage_id, storage_directory_e type, char **p if (extendedint) return STORAGE_ERROR_INVALID_PARAMETER; - if ((ret = snprintf(temp, sizeof(temp), "%s/%s", root, dir_path[type])) > sizeof(temp) - 1) { - _E("Path is longer than buffer. Need %d size of buffer.", ret + 1); + if ((ret_val = snprintf(temp, sizeof(temp), "%s/%s", root, dir_path[type])) > sizeof(temp) - 1) { + _E("Path is longer than buffer. Need %d size of buffer.", ret_val + 1); return STORAGE_ERROR_OUT_OF_MEMORY; } @@ -273,7 +273,7 @@ API int storage_get_type(int storage_id, storage_type_e *type) const struct storage_ops *st; GList *elem; char root[PATH_MAX]; - int ret; + int ret_val; bool extendedint; if (storage_id < 0) @@ -298,12 +298,12 @@ API int storage_get_type(int storage_id, storage_type_e *type) return STORAGE_ERROR_NOT_SUPPORTED; } - ret = storage_ext_get_root(storage_id, root, sizeof(root), &extendedint); - if (ret < 0) { + ret_val = storage_ext_get_root(storage_id, root, sizeof(root), &extendedint); + if (ret_val < 0) { _E("Failed to get type of external storage"); - if (ret == -ENODEV || ret == -EINVAL) + if (ret_val == -ENODEV || ret_val == -EINVAL) return STORAGE_ERROR_INVALID_PARAMETER; - else if (ret == -ENOMEM) + else if (ret_val == -ENOMEM) return STORAGE_ERROR_OUT_OF_MEMORY; else return STORAGE_ERROR_OPERATION_FAILED; @@ -321,7 +321,7 @@ API int storage_get_state(int storage_id, storage_state_e *state) const struct storage_ops *ops; storage_state_e st; GList *elem; - int ret; + int ret_val; if (storage_id < 0) return STORAGE_ERROR_INVALID_PARAMETER; @@ -345,12 +345,12 @@ API int storage_get_state(int storage_id, storage_state_e *state) return STORAGE_ERROR_NOT_SUPPORTED; } - ret = storage_ext_get_state(storage_id, &st); - if (ret < 0) { - _E("Failed to get state (storage id(%d), ret(%d))", storage_id, ret); //LCOV_EXCL_LINE - if (ret == -ENODEV || ret == -EINVAL) + ret_val = storage_ext_get_state(storage_id, &st); + if (ret_val < 0) { + _E("Failed to get state (storage id(%d), ret_val(%d))", storage_id, ret_val); //LCOV_EXCL_LINE + if (ret_val == -ENODEV || ret_val == -EINVAL) return STORAGE_ERROR_INVALID_PARAMETER; - else if (ret == -ENOMEM) + else if (ret_val == -ENOMEM) return STORAGE_ERROR_OUT_OF_MEMORY; else return STORAGE_ERROR_OPERATION_FAILED; @@ -446,7 +446,7 @@ API int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb { const struct storage_ops *st; struct storage_cb_info info; - int ret; + int ret_val; GList *elem; if (storage_id < 0) @@ -491,8 +491,8 @@ API int storage_unset_state_changed_cb(int storage_id, storage_state_changed_cb info.id = storage_id; info.state_cb = callback; - ret = storage_ext_unregister_cb(STORAGE_CALLBACK_ID, &info); - if (ret < 0) { + ret_val = storage_ext_unregister_cb(STORAGE_CALLBACK_ID, &info); + if (ret_val < 0) { _E("Failed to unregister callback : id(%d)", storage_id); //LCOV_EXCL_LINE return STORAGE_ERROR_OPERATION_FAILED; } @@ -504,7 +504,7 @@ API int storage_get_total_space(int storage_id, unsigned long long *bytes) { const struct storage_ops *st; unsigned long long total; - int ret; + int ret_val; GList *elem; if (storage_id < 0) @@ -519,7 +519,7 @@ API int storage_get_total_space(int storage_id, unsigned long long *bytes) SYS_G_LIST_FOREACH(st_int_head, elem, st) { if (st->storage_id != storage_id) continue; - ret = st->get_space(&total, NULL); + ret_val = st->get_space(&total, NULL); goto out; } @@ -529,14 +529,14 @@ API int storage_get_total_space(int storage_id, unsigned long long *bytes) return STORAGE_ERROR_NOT_SUPPORTED; } - ret = storage_ext_get_space(storage_id, &total, NULL); + ret_val = storage_ext_get_space(storage_id, &total, NULL); out: - if (ret < 0) { + if (ret_val < 0) { _E("Failed to get total memory : id(%d)", storage_id); //LCOV_EXCL_LINE - if (ret == -ENODEV || ret == -EINVAL) + if (ret_val == -ENODEV || ret_val == -EINVAL) return STORAGE_ERROR_INVALID_PARAMETER; - else if (ret == -ENOMEM) + else if (ret_val == -ENOMEM) return STORAGE_ERROR_OUT_OF_MEMORY; else return STORAGE_ERROR_OPERATION_FAILED; @@ -550,7 +550,7 @@ API int storage_get_available_space(int storage_id, unsigned long long *bytes) { const struct storage_ops *st; unsigned long long avail; - int ret; + int ret_val; GList *elem; if (storage_id < 0) @@ -565,7 +565,7 @@ API int storage_get_available_space(int storage_id, unsigned long long *bytes) SYS_G_LIST_FOREACH(st_int_head, elem, st) { if (st->storage_id != storage_id) continue; - ret = st->get_space(NULL, &avail); + ret_val = st->get_space(NULL, &avail); goto out; } @@ -575,14 +575,14 @@ API int storage_get_available_space(int storage_id, unsigned long long *bytes) return STORAGE_ERROR_NOT_SUPPORTED; } - ret = storage_ext_get_space(storage_id, NULL, &avail); + ret_val = storage_ext_get_space(storage_id, NULL, &avail); out: - if (ret < 0) { + if (ret_val < 0) { _E("Failed to get available memory : id(%d)", storage_id); //LCOV_EXCL_LINE - if (ret == -ENODEV || ret == -EINVAL) + if (ret_val == -ENODEV || ret_val == -EINVAL) return STORAGE_ERROR_INVALID_PARAMETER; - else if (ret == -ENOMEM) + else if (ret_val == -ENOMEM) return STORAGE_ERROR_OUT_OF_MEMORY; else return STORAGE_ERROR_OPERATION_FAILED; @@ -594,7 +594,7 @@ out: API int storage_set_changed_cb(storage_type_e type, storage_changed_cb callback, void *user_data) { - int ret; + int ret_val; struct storage_cb_info info; if (type == STORAGE_TYPE_INTERNAL) { @@ -622,9 +622,9 @@ API int storage_set_changed_cb(storage_type_e type, storage_changed_cb callback, info.type_cb = callback; info.user_data = user_data; - ret = storage_ext_register_cb(STORAGE_CALLBACK_TYPE, &info); - if (ret < 0) { - _E("Failed to register storage callback(ret:%d)", ret); //LCOV_EXCL_LINE + ret_val = storage_ext_register_cb(STORAGE_CALLBACK_TYPE, &info); + if (ret_val < 0) { + _E("Failed to register storage callback(ret:%d)", ret_val); //LCOV_EXCL_LINE return STORAGE_ERROR_OPERATION_FAILED; } @@ -634,7 +634,7 @@ API int storage_set_changed_cb(storage_type_e type, storage_changed_cb callback, API int storage_unset_changed_cb(storage_type_e type, storage_changed_cb callback) { struct storage_cb_info info; - int ret; + int ret_val; if (type == STORAGE_TYPE_INTERNAL) { _E("Internal storage is not supported"); @@ -660,9 +660,9 @@ API int storage_unset_changed_cb(storage_type_e type, storage_changed_cb callbac info.type = type; info.type_cb = callback; - ret = storage_ext_unregister_cb(STORAGE_CALLBACK_TYPE, &info); - if (ret < 0) { - _E("Failed to unregister storage callback(ret:%d)", ret); //LCOV_EXCL_LINE + ret_val = storage_ext_unregister_cb(STORAGE_CALLBACK_TYPE, &info); + if (ret_val < 0) { + _E("Failed to unregister storage callback(ret:%d)", ret_val); //LCOV_EXCL_LINE return STORAGE_ERROR_OPERATION_FAILED; } -- 2.7.4 From 7a7bfe253ba0b10efd207794d7ce3f439b444658 Mon Sep 17 00:00:00 2001 From: "taemin.yeom" Date: Fri, 19 Mar 2021 17:01:30 +0900 Subject: [PATCH 12/16] Change dbus function name Change-Id: I6f6aabf82a4f9e63b1ac678579cafaed5299767b Signed-off-by: taemin.yeom --- src/storage-external-dbus.c | 16 ++++++++-------- src/storage-inhouse.c | 10 +++++----- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index 1b71d56..b94e311 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include "log.h" @@ -104,7 +104,7 @@ int storage_ext_get_list(GList **list) if (!list) return -EINVAL; - ret_dbus = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, + ret_dbus = gdbus_call_sync_with_reply(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, STORAGE_EXT_GET_LIST, @@ -173,7 +173,7 @@ int storage_ext_get_statvfs(char *path, struct statvfs_32 *buf) memset(buf, 0, sizeof(struct statvfs_32)); - ret_dbus = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, + ret_dbus = gdbus_call_sync_with_reply(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_STORAGE, STORAGE_EXT_IFACE_STORAGE, STORAGE_EXT_GET_STATVFS, @@ -220,7 +220,7 @@ int storage_ext_get_statvfs_size64(char *path, struct statvfs *buf) memset(buf, 0, sizeof(struct statvfs)); - ret_dbus = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, + ret_dbus = gdbus_call_sync_with_reply(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_STORAGE, STORAGE_EXT_IFACE_STORAGE, STORAGE_EXT_GET_STATVFS, @@ -265,7 +265,7 @@ int storage_ext_get_storage_level(const char *path, char **level) return -EINVAL; } - ret_dbus = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, + ret_dbus = gdbus_call_sync_with_reply(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_STORAGE, STORAGE_EXT_IFACE_STORAGE, STORAGE_EXT_GET_STORAGE_LEVEL, @@ -407,7 +407,7 @@ int storage_ext_register_device_change(storage_ext_changed_cb func, void *data) //LCOV_EXCL_STOP } - block_id = subscribe_dbus_signal(NULL, NULL, + block_id = gdbus_signal_subscribe(NULL, NULL, STORAGE_EXT_IFACE_MANAGER, NULL, storage_ext_changed, @@ -443,7 +443,7 @@ void storage_ext_unregister_device_change(storage_ext_changed_cb func) if (callback->func != func) continue; if (callback->block_id > 0) - unsubscribe_dbus_signal(NULL, callback->block_id); + gdbus_signal_unsubscribe(NULL, callback->block_id); SYS_G_LIST_REMOVE(changed_list, callback); free(callback); @@ -455,7 +455,7 @@ int storage_ext_get_device_info(int storage_id, storage_ext_device *info) GVariant *reply; int ret_dbus; - ret_dbus = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, + ret_dbus = gdbus_call_sync_with_reply(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, "GetDeviceInfo", diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index c2d5d1b..1d89af4 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include "common.h" #include "log.h" @@ -174,7 +174,7 @@ API int storage_get_primary_sdcard(int *storage_id, char **path) if (!storage_ext_is_supported()) return STORAGE_ERROR_NOT_SUPPORTED; - ret_dbus = dbus_handle_method_sync_with_reply_var(STORAGE_EXT_BUS_NAME, + ret_dbus = gdbus_call_sync_with_reply(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, "GetMmcPrimary", @@ -285,7 +285,7 @@ API int storage_request_mount_mmc(struct mmc_contents *mmc_data) free(path); //LCOV_EXCL_STOP - ret_val = dbus_handle_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, + ret_val = gdbus_call_async_with_reply(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, "Mount", @@ -354,7 +354,7 @@ API int storage_request_unmount_mmc(struct mmc_contents *mmc_data, int option) free(path); //LCOV_EXCL_STOP - ret_val = dbus_handle_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, + ret_val = gdbus_call_async_with_reply(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, "Unmount", @@ -428,7 +428,7 @@ API int storage_format_mmc(struct mmc_contents *mmc_data, int option) free(path); //LCOV_EXCL_STOP - ret_val = dbus_handle_method_async_with_reply_var(STORAGE_EXT_BUS_NAME, + ret_val = gdbus_call_async_with_reply(STORAGE_EXT_BUS_NAME, STORAGE_EXT_PATH_MANAGER, STORAGE_EXT_IFACE_MANAGER, "Format", -- 2.7.4 From 37e9fd39dee8184ecbf7b55eb52c4919a526298d Mon Sep 17 00:00:00 2001 From: Yunmi Ha Date: Mon, 5 Jul 2021 20:42:02 +0900 Subject: [PATCH 13/16] Support container path when checking "opt/user" is mounted. Change-Id: Ie0c1474258eafcd93634784fed58da74703544ca Signed-off-by: Yunmi Ha --- CMakeLists.txt | 2 +- src/storage-inhouse.c | 12 ++++++++---- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 539311a..1f6875c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -22,7 +22,7 @@ SET(dependents capi-system-info libsyscommon ) -SET(pc_dependents "capi-base-common") +SET(PC_REQUIRED "capi-base-common") INCLUDE(FindPkgConfig) pkg_check_modules(rpkgs REQUIRED ${dependents}) diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index 1d89af4..45aba82 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -24,6 +24,7 @@ #include #include #include +#include #include "common.h" #include "log.h" @@ -32,6 +33,7 @@ #define FORMAT_TIMEOUT (120*1000) #define USER_PARTITION "user" +#define CONTAINER_USER_PARTITION "contain-user" /* Get compat path from origin Multi-user path @@ -454,10 +456,12 @@ API int storage_is_mounted_opt_usr(storage_part_mount_e *mounted) blkid_dev dev; int ret_val; bool found = false; + char *user_label = is_container()? CONTAINER_USER_PARTITION: USER_PARTITION; if (!mounted) return STORAGE_ERROR_INVALID_PARAMETER; + _D("Find user partition label: %s", user_label); ret_val = blkid_get_cache(&cache, NULL); if (ret_val < 0) { _E("Failed to get cache"); //LCOV_EXCL_LINE @@ -479,12 +483,12 @@ API int storage_is_mounted_opt_usr(storage_part_mount_e *mounted) return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE } - ret_val = blkid_dev_set_search(iter, "LABEL", USER_PARTITION); + ret_val = blkid_dev_set_search(iter, "LABEL", user_label); if (blkid_dev_next(iter, &dev) == 0) { dev = blkid_verify(cache, dev); if (dev) { found = true; - _D("Partition for user data is found(LABEL=user)"); + _D("Partition for user data is found(LABEL=%s)", user_label); } } blkid_dev_iterate_end(iter); @@ -497,12 +501,12 @@ API int storage_is_mounted_opt_usr(storage_part_mount_e *mounted) return STORAGE_ERROR_OUT_OF_MEMORY; //LCOV_EXCL_LINE } - ret_val = blkid_dev_set_search(iter, "PARTLABEL", USER_PARTITION); + ret_val = blkid_dev_set_search(iter, "PARTLABEL", user_label); if (blkid_dev_next(iter, &dev) == 0) { dev = blkid_verify(cache, dev); if (dev) { found = true; - _D("Partition for user data is found(PARTLABEL=user)"); + _D("Partition for user data is found(PARTLABEL=%s)", user_label); } } blkid_dev_iterate_end(iter); -- 2.7.4 From 08d10226717198956dec6aaac7edd7c6310d4bf4 Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Tue, 25 Jan 2022 21:50:17 -0800 Subject: [PATCH 14/16] Change gcov object install path Change-Id: I9cf872fe5b9badcc042a0c850e194a3c7467e21b Signed-off-by: Youngjae Cho --- packaging/libstorage.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packaging/libstorage.spec b/packaging/libstorage.spec index e6d2da5..bf89f7d 100644 --- a/packaging/libstorage.spec +++ b/packaging/libstorage.spec @@ -62,8 +62,8 @@ find . -name '*.gcno' -exec cp '{}' gcov-obj ';' %make_install %if 0%{?gcov:1} -mkdir -p %{buildroot}%{_datadir}/gcov/obj -install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj +mkdir -p %{buildroot}%{_datadir}/gcov/obj/%{name} +install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj/%{name} %endif %post -p /sbin/ldconfig -- 2.7.4 From 9dbae7c62e720b1634208976525254b318765c75 Mon Sep 17 00:00:00 2001 From: Hyotaek Shim Date: Wed, 13 Apr 2022 14:50:11 +0900 Subject: [PATCH 15/16] Use libsys_is_container() Change-Id: I1ec302f6ecf34f760103ad178987fed107602527 Signed-off-by: Hyotaek Shim --- src/storage-inhouse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/storage-inhouse.c b/src/storage-inhouse.c index 45aba82..68b0c20 100755 --- a/src/storage-inhouse.c +++ b/src/storage-inhouse.c @@ -456,7 +456,7 @@ API int storage_is_mounted_opt_usr(storage_part_mount_e *mounted) blkid_dev dev; int ret_val; bool found = false; - char *user_label = is_container()? CONTAINER_USER_PARTITION: USER_PARTITION; + char *user_label = libsys_is_container()? CONTAINER_USER_PARTITION: USER_PARTITION; if (!mounted) return STORAGE_ERROR_INVALID_PARAMETER; -- 2.7.4 From a41903e9780f31936cd9a6bfe2ae32368bdbc05e Mon Sep 17 00:00:00 2001 From: Youngjae Cho Date: Fri, 10 Jun 2022 10:09:26 +0900 Subject: [PATCH 16/16] Apply requirement for gcov automation Change-Id: I92c4e7d386defcdee2467a6153faf51735f692d5 Signed-off-by: Youngjae Cho --- packaging/libstorage.spec | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/packaging/libstorage.spec b/packaging/libstorage.spec index bf89f7d..1763bbd 100644 --- a/packaging/libstorage.spec +++ b/packaging/libstorage.spec @@ -47,23 +47,22 @@ cp %{SOURCE1} . %build %if 0%{?gcov:1} export CFLAGS+=" -fprofile-arcs -ftest-coverage" +export CXXFLAGS+=" -fprofile-arcs -ftest-coverage" +export FFLAGS+=" -fprofile-arcs -ftest-coverage" export LDFLAGS+=" -lgcov" %endif %cmake . make %{?jobs:-j%jobs} -%if 0%{?gcov:1} -mkdir -p gcov-obj -find . -name '*.gcno' -exec cp '{}' gcov-obj ';' -%endif - %install %make_install %if 0%{?gcov:1} -mkdir -p %{buildroot}%{_datadir}/gcov/obj/%{name} -install -m 0644 gcov-obj/* %{buildroot}%{_datadir}/gcov/obj/%{name} +builddir=$(basename $PWD) +gcno_obj_dir=%{buildroot}%{_datadir}/gcov/obj/%{name}/"$builddir" +mkdir -p "$gcno_obj_dir" +find . -name '*.gcno' -exec cp --parents '{}' "$gcno_obj_dir" ';' %endif %post -p /sbin/ldconfig -- 2.7.4