+++ /dev/null
-/*
- * deviced
- *
- * Copyright (c) 2012 - 2013 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 __DD_MMC_H__
-#define __DD_MMC_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/**
- * @file dd-mmc.h
- * @defgroup CAPI_SYSTEM_DEVICED_MMC_MODULE MMC
- * @ingroup CAPI_SYSTEM_DEVICED
- * @brief This file provides the API for control of mmc(sd-card)
- * @section CAPI_SYSTEM_DEVICED_MMC_MODULE_HEADER Required Header
- * \#include <dd-mmc.h>
- */
-
-/**
- * @addtogroup CAPI_SYSTEM_DEVICED_MMC_MODULE
- * @{
- */
-
-/**
- * @brief This structure defines the data for receive result of mmc operations(mount/unmount/format)
- */
-struct mmc_contents {
- void (*mmc_cb) (int result, void* data);/**< user callback function for receive result of mmc operations */
- void* user_data;/**< input data for callback function's second-param(data) */
-};
-
-/**
- * @fn int deviced_request_mount_mmc(struct mmc_contents *mmc_data)
- * @brief This API is used to mount mmc.\n
- * Internally, this API call predefined action API. That is send a notify message. \n
- * and when mount operation is finished, cb of deviced_mmc_content struct is called with cb's param1(result). \n
- * means of param1 - 0(mount success) and negative value if failed \n
- * [mount fail value] \n
- * -1 : operation not permmitted \n
- * -2 : no such file or directory \n
- * -6 : no such device or address \n
- * -12 : out of memory \n
- * -13 : A component of a path was not searchable \n
- * -14 : bad address \n
- * -15 : block device is requested \n
- * -16 : device or resource busy \n
- * -19 : filesystemtype not configured in the kernel \n
- * -20 : target, or a prefix of source, is not a directory \n
- * -22 : point does not exist \n
- * -24 : table of dummy devices is full \n
- * -36 : requested name is too long \n
- * -40 : Too many links encountered during pathname resolution. \n
- * Or, a move was attempted, while target is a descendant of source \n
- * @param[in] mmc_data for receive result of mount operation
- * @return non-zero on success message sending, -1 if message sending is failed.
- */
-int deviced_request_mount_mmc(struct mmc_contents *mmc_data);
-
-/**
- * @fn int deviced_request_unmount_mmc(struct mmc_contents *mmc_data,int option)
- * @brief This API is used to unmount mmc.\n
- * Internally, this API call predefined action API. That is send a notify message. \n
- * and when unmount opeation is finished, cb of deviced_mmc_content struct is called with cb's param1(result). \n
- * means of param1 - 0(unmount success) and negative value if failed \n
- * [unmount fail value] \n
- * -1 : operation not permmitted \n
- * -2 : no such file or directory \n
- * -11 : try again \n
- * -12 : out of memory \n
- * -14 : bad address \n
- * -16 : device or resource busy \n
- * -22 : point does not exist \n
- * -36 : requested name is too long \n
- * @param[in] mmc_data for receive result of unmount operation
- * @param[in] option type of unmount option \n
- * 0 : Normal unmount \n
- * (if other process still access a sdcard, \n
- * unmount will be failed.) \n
- * 1 : Force unmount \n
- * (if other process still access a sdcard, \n
- * this process will be received SIGTERM or SIGKILL.)
- * @return non-zero on success message sending, -1 if message sending is failed.
- */
-int deviced_request_unmount_mmc(struct mmc_contents *mmc_data, int option);
-
-/**
- * @fn int deviced_request_format_mmc(struct mmc_contents *mmc_data)
- * @brief This API is used to format mmc.\n
- * Internally, this API call predefined action API. That is send a notify message. \n
- * and when format opeation is finished, cb of deviced_mmc_content struct is called with cb's param1(result). \n
- * means of param1 - 0(format success) , -1(format fail)
- * @param[in] mmc_data for receive result of format operation
- * @return non-zero on success message sending, -1 if message sending is failed.
- */
-int deviced_request_format_mmc(struct mmc_contents *mmc_data);
-
-/**
- * @fn int deviced_format_mmc(struct mmc_contents *mmc_data, int option)
- * @brief This API is used to format mmc.\n
- * Internally, this API call predefined action API. That is send a notify message. \n
- * and when format opeation is finished, cb of deviced_mmc_content struct is called with cb's param1(result). \n
- * means of param1 - 0(format success) and negative value if failed \n
- * [format fail value] \n
- * -22 : Invalid argument(EINVAL) \n
- * @param[in] mmc_data for receive result of format operation
- * @param[in] option FMT_NORMAL is 0, FMT_FORCE is 1
- * @return non-zero on success message sending, -1 if message sending is failed.
- */
-int deviced_format_mmc(struct mmc_contents *mmc_data, int option);
-
-/**
- * @} // end of CAPI_SYSTEM_DEVICED_MMC_MODULE
- */
-
-#ifdef __cplusplus
-}
-#endif
-#endif
+++ /dev/null
-/*
- * deviced
- *
- * Copyright (c) 2012 - 2013 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.
- */
-
-
-#include <stdio.h>
-#include <vconf.h>
-#include <errno.h>
-#include <stdbool.h>
-#include <glib.h>
-#include <libgdbus/dbus-system.h>
-
-#include "log.h"
-#include "common.h"
-#include "dd-mmc.h"
-
-#define ODE_MOUNT_STATE 1
-
-#define FORMAT_TIMEOUT (120*1000)
-#define STORAGE_MMC 1
-#define BUF_MAX 256
-
-static int get_mmc_primary_id()
-{
- GVariant *reply;
- GVariantIter *iter;
- int type;
- char *devnode = NULL;
- bool primary;
- int ret;
- int id;
-
- reply = dbus_handle_method_sync_with_reply_var(STORAGED_BUS_NAME,
- STORAGED_PATH_BLOCK_MANAGER,
- STORAGED_INTERFACE_BLOCK_MANAGER,
- "GetDeviceList",
- g_variant_new("(s)", "mmc"));
- if (!reply) {
- _E("Failed to get mmc storage list");
- return -EPERM;
- }
-
- //dbus_message_iter_init(reply, &iter);
- //dbus_message_iter_recurse(&iter, &aiter);
-
- //while (dbus_message_iter_get_arg_type(&aiter) != DBUS_TYPE_INVALID) {
- // devnode = NULL;
- // dbus_message_iter_recurse(&aiter, &piter); /*type*/
- // dbus_message_iter_get_basic(&piter, &type);
- // dbus_message_iter_next(&piter); /* devnode */
- // dbus_message_iter_get_basic(&piter, &devnode);
- // dbus_message_iter_next(&piter); /* syspath */
- // dbus_message_iter_next(&piter); /* fsusage */
- // dbus_message_iter_next(&piter); /* fstype */
- // dbus_message_iter_next(&piter); /* fsversion */
- // dbus_message_iter_next(&piter); /* fsuuid */
- // dbus_message_iter_next(&piter); /* readonly */
- // dbus_message_iter_next(&piter); /* mountpath */
- // dbus_message_iter_next(&piter); /* state */
- // dbus_message_iter_next(&piter); /* primary */
- // dbus_message_iter_get_basic(&piter, &primary);
- // dbus_message_iter_next(&piter); /* flags */
- // dbus_message_iter_next(&piter); /* storage id */
- // dbus_message_iter_get_basic(&piter, &id);
- // dbus_message_iter_next(&aiter);
-
- // if (type == STORAGE_MMC && primary && devnode)
- // break;
- //}
- if (!dh_get_param_from_var(reply, "(a(issssssisibii))", &iter)) {
- _E("Failed to get mmc storage list, wrong signature:%s", g_variant_get_type_string(reply));
- return -EPERM;
- }
-
- while (g_variant_iter_loop(iter, "(issssssisibii)",
- &type, &devnode, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, &primary, NULL, &id)) {
- if (type == STORAGE_MMC && primary && devnode)
- break;
- devnode = NULL;
- }
-
- if (devnode)
- ret = id;
- else
- ret = -ENODEV;
-
- g_variant_iter_free(iter);
- g_variant_unref(reply);
-
- return ret;
-}
-
-static void mount_mmc_cb(GVariant *var, void *user_data, GError *err)
-{
- struct mmc_contents *mmc_data = (struct mmc_contents*)user_data;
- int mmc_ret;
-
- _D("mount_mmc_cb called");
-
- if (!var) {
- _E("no message [%s]", err->message);
- mmc_ret = -EBADMSG;
- goto exit;
- }
-
- if (!dh_get_param_from_var(var, "(i)", &mmc_ret)) {
- _E("fail (signature:%s): no message", g_variant_get_type_string(var));
- mmc_ret = -EBADMSG;
- goto exit;
- }
-
- _I("Mount State : %d", mmc_ret);
-
-exit:
- if (var)
- g_variant_unref(var);
- (mmc_data->mmc_cb)(mmc_ret, mmc_data->user_data);
-}
-
-API int deviced_request_mount_mmc(struct mmc_contents *mmc_data)
-{
- void (*mount_cb)(GVariant *, void *, GError *) = NULL;
- void *data = NULL;
- int ret;
- int id;
-
- if (mmc_data && mmc_data->mmc_cb) {
- _I("Mount callback exists");
- mount_cb = mount_mmc_cb;
- data = mmc_data;
- }
-
- id = get_mmc_primary_id();
- if (id < 0)
- return id;
-
- ret = dbus_handle_method_async_with_reply_var(STORAGED_BUS_NAME,
- STORAGED_PATH_BLOCK_MANAGER,
- STORAGED_INTERFACE_BLOCK_MANAGER,
- "Mount",
- g_variant_new("(is)", id, ""),
- mount_cb,
- -1,
- data);
-
- _I("Mount Request %s", ret == 0 ? "Success" : "Failed");
-
- return ret;
-}
-
-static void unmount_mmc_cb(GVariant *var, void *user_data, GError *err)
-{
- struct mmc_contents *mmc_data = (struct mmc_contents*)user_data;
- int mmc_ret;
-
- _D("unmount_mmc_cb called");
-
- if (!var) {
- _E("no message [%s]", err->message);
- mmc_ret = -EBADMSG;
- goto exit;
- }
-
- if (!dh_get_param_from_var(var, "(i)", &mmc_ret)) {
- _E("fail (signature:%s): no message", g_variant_get_type_string(var));
- mmc_ret = -EBADMSG;
- goto exit;
- }
-
- _I("Unmount State : %d", mmc_ret);
-
-exit:
- if (var)
- g_variant_unref(var);
- (mmc_data->mmc_cb)(mmc_ret, mmc_data->user_data);
-}
-
-API int deviced_request_unmount_mmc(struct mmc_contents *mmc_data, int option)
-{
- void (*unmount_cb)(GVariant *, void *, GError *) = NULL;
- void *data = NULL;
- int ret;
- int id;
-
- if (option < 0 || option > 1)
- return -EINVAL;
-
- if (mmc_data && mmc_data->mmc_cb) {
- _I("Mount callback exists");
- unmount_cb = unmount_mmc_cb;
- data = mmc_data;
- }
-
- id = get_mmc_primary_id();
- if (id < 0)
- return id;
-
- ret = dbus_handle_method_async_with_reply_var(STORAGED_BUS_NAME,
- STORAGED_PATH_BLOCK_MANAGER,
- STORAGED_INTERFACE_BLOCK_MANAGER,
- "Unmount",
- g_variant_new("(ii)", id, option),
- unmount_cb,
- -1,
- data);
-
- _I("Unmount Request %s", ret == 0 ? "Success" : "Failed");
-
- return ret;
-}
-
-static void format_mmc_cb(GVariant *var, void *user_data, GError *err)
-{
- struct mmc_contents *mmc_data = (struct mmc_contents*)user_data;
- int mmc_ret;
-
- _D("format_mmc_cb called");
-
- if (!var) {
- _E("no message [%s]", err->message);
- mmc_ret = -EBADMSG;
- goto exit;
- }
-
- if (!dh_get_param_from_var(var, "(i)", &mmc_ret)) {
- _E("fail (signature:%s): no message", g_variant_get_type_string(var));
- mmc_ret = -EBADMSG;
- goto exit;
- }
-
- _I("Format State : %d", mmc_ret);
-
-exit:
- if (var)
- g_variant_unref(var);
- (mmc_data->mmc_cb)(mmc_ret, mmc_data->user_data);
-}
-
-API int deviced_request_format_mmc(struct mmc_contents *mmc_data)
-{
- return deviced_format_mmc(mmc_data, 1);
-}
-
-API int deviced_format_mmc(struct mmc_contents *mmc_data, int option)
-{
- void (*format_cb)(GVariant *, void *, GError *) = NULL;
- void *data = NULL;
- int ret;
- int id;
-
- if (option < 0 || option > 1)
- return -EINVAL;
-
- if (mmc_data && mmc_data->mmc_cb) {
- _I("Mount callback exists");
- format_cb = format_mmc_cb;
- data = mmc_data;
- }
-
- id = get_mmc_primary_id();
- if (id < 0)
- return id;
-
- ret = dbus_handle_method_async_with_reply_var(STORAGED_BUS_NAME,
- STORAGED_PATH_BLOCK_MANAGER,
- STORAGED_INTERFACE_BLOCK_MANAGER,
- "Format",
- g_variant_new("(ii)", id, option),
- format_cb,
- FORMAT_TIMEOUT,
- data);
-
- _I("Format Request %s", ret == 0 ? "Success" : "Failed");
-
- return ret;
-}