From bccbe0277184d6f26b259da0f21e2c90b1121ebd Mon Sep 17 00:00:00 2001 From: taeyoung Date: Thu, 14 Jul 2016 20:59:55 +0900 Subject: [PATCH] mmc: add the internal api to return primary mmc information - Primary mmc information is used to install apps on the mmc. Thus primary mmc information api is necessary to avoid iterations with previous apis Change-Id: Id27f575d0442225d0cb909220716e5d527ad506d Signed-off-by: taeyoung --- CMakeLists.txt | 6 ++-- include/storage-internal.h | 63 +++++++++++++++++++++++++++++++++++++++ src/storage-external-dbus.c | 4 +-- src/storage-external-dbus.h | 4 +++ src/storage-external-inhouse.c | 67 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 140 insertions(+), 4 deletions(-) create mode 100644 include/storage-internal.h create mode 100755 src/storage-external-inhouse.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 56482b0..55924cd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -30,7 +30,8 @@ ENDFOREACH(flag) SET(HEADERS include/storage.h - include/storage-expand.h) + include/storage-expand.h + include/storage-internal.h) SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -fvisibility=hidden") SET(EXTRA_CFLAGS "${EXTRA_CFLAGS} -g") @@ -45,7 +46,8 @@ SET(SRCS src/storage.c src/storage-internal.c src/storage-external.c - src/storage-external-dbus.c) + src/storage-external-dbus.c + src/storage-external-inhouse.c) ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRCS} ${TARGET_SRCS}) TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${rpkgs_LDFLAGS}) diff --git a/include/storage-internal.h b/include/storage-internal.h new file mode 100644 index 0000000..2040fc9 --- /dev/null +++ b/include/storage-internal.h @@ -0,0 +1,63 @@ +/* + * storage + * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * + * 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 __STORAGE_INTERNAL_H__ +#define __STORAGE_INTERNAL_H__ + +#ifdef __cplusplus +extern "C" { +#endif + + +/** + * @addtogroup CAPI_SYSTEM_STORAGE_MODULE + * @{ + */ + +#include +#include "storage.h" + +#define STORAGE_ERROR_NO_DEVICE TIZEN_ERROR_NO_SUCH_DEVICE + +/** + * @brief Get the mount path for the primary partition of sdcard. + * + * @since_tizen 3.0 + * + * @remarks You must release the path using free() after use + * + * @param[out] storage_id The storage id + * @param[out] path The mount path of sdcard primary partition. + * + * @return @c 0 on success, + * otherwise a negative error value + * + * @retval #STORAGE_ERROR_NONE Successful + * @retval #STORAGE_ERROR_INVALID_PARAMETER Invalid parameter + * @retval #STORAGE_ERROR_NO_DEVICE No such device + */ +int storage_get_primary_sdcard(int *storage_id, char **path); + +/** + * @} + */ + +#ifdef __cplusplus +} +#endif +#endif /* __STORAGE_INTERNAL_H__ */ diff --git a/src/storage-external-dbus.c b/src/storage-external-dbus.c index 2793e40..012044c 100755 --- a/src/storage-external-dbus.c +++ b/src/storage-external-dbus.c @@ -112,14 +112,14 @@ static GDBusConnection *get_dbus_connection(void) return conn; } -static GVariant *dbus_method_call_sync(const gchar *dest, const gchar *path, +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 || !param) + if (!dest || !path || !iface || !method) return NULL; conn = get_dbus_connection(); diff --git a/src/storage-external-dbus.h b/src/storage-external-dbus.h index d279c65..06153ee 100644 --- a/src/storage-external-dbus.h +++ b/src/storage-external-dbus.h @@ -84,4 +84,8 @@ void storage_ext_unregister_device_change(storage_ext_changed_cb func); int storage_ext_get_device_info(int storage_id, storage_ext_device *info); +/* 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-inhouse.c b/src/storage-external-inhouse.c new file mode 100755 index 0000000..6e7f5c4 --- /dev/null +++ b/src/storage-external-inhouse.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2016 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. + */ + + +#include +#include +#include +#include + +#include "common.h" +#include "list.h" +#include "log.h" +#include "storage-internal.h" +#include "storage-external-dbus.h" + +API int storage_get_primary_sdcard(int *storage_id, char **path) +{ + GVariant *result; + storage_ext_device info; + + if (!storage_id || !path) + return STORAGE_ERROR_INVALID_PARAMETER; + + result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME, + STORAGE_EXT_PATH_MANAGER, + STORAGE_EXT_IFACE_MANAGER, + "GetMmcPrimary", + NULL); + if (!result) { + _E("Failed to get primary sdcard partition"); //LCOV_EXCL_LINE + return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE + } + + 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); + + g_variant_unref(result); + + if (info.storage_id < 0) + return STORAGE_ERROR_NO_DEVICE; + + *path = strdup(info.mount_point); + if (*path == NULL) + return STORAGE_ERROR_OUT_OF_MEMORY; + + *storage_id = info.storage_id; + + return STORAGE_ERROR_NONE; +} -- 2.7.4