mmc: add the internal api to return primary mmc information
[platform/core/system/libstorage.git] / src / storage-external-inhouse.c
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <string.h>
21 #include <errno.h>
22
23 #include "common.h"
24 #include "list.h"
25 #include "log.h"
26 #include "storage-internal.h"
27 #include "storage-external-dbus.h"
28
29 API int storage_get_primary_sdcard(int *storage_id, char **path)
30 {
31         GVariant *result;
32         storage_ext_device info;
33
34         if (!storage_id || !path)
35                 return STORAGE_ERROR_INVALID_PARAMETER;
36
37         result = dbus_method_call_sync(STORAGE_EXT_BUS_NAME,
38                         STORAGE_EXT_PATH_MANAGER,
39                         STORAGE_EXT_IFACE_MANAGER,
40                         "GetMmcPrimary",
41                         NULL);
42         if (!result) {
43                 _E("Failed to get primary sdcard partition"); //LCOV_EXCL_LINE
44                 return STORAGE_ERROR_OPERATION_FAILED; //LCOV_EXCL_LINE
45         }
46
47         g_variant_get(result, "(issssssisibii)",
48                         &info.type, &info.devnode, &info.syspath,
49                         &info.fs_usage, &info.fs_type,
50                         &info.fs_version, &info.fs_uuid,
51                         &info.readonly, &info.mount_point,
52                         &info.state, &info.primary,
53                         &info.flags, &info.storage_id);
54
55         g_variant_unref(result);
56
57         if (info.storage_id < 0)
58                 return STORAGE_ERROR_NO_DEVICE;
59
60         *path = strdup(info.mount_point);
61         if (*path == NULL)
62                 return STORAGE_ERROR_OUT_OF_MEMORY;
63
64         *storage_id = info.storage_id;
65
66         return STORAGE_ERROR_NONE;
67 }