internal: storage list is used just for internal storage
[platform/core/system/libstorage.git] / src / storage-internal.c
1 /*
2  * Copyright (c) 2011 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 #include <limits.h>
23 #include <sys/statvfs.h>
24 #include <tzplatform_config.h>
25
26 #include "common.h"
27 #include "log.h"
28
29
30 #ifndef __USE_FILE_OFFSET64
31 int __WEAK__ storage_get_internal_memory_size(struct statvfs *buf);
32 #else
33 int __WEAK__ storage_get_internal_memory_size64(struct statvfs *buf);
34 #endif
35
36 static int internal_get_state(void)
37 {
38         return STORAGE_STATE_MOUNTED;
39 }
40
41 static int internal_get_space(unsigned long long *total, unsigned long long *available)
42 {
43         struct statvfs s;
44         int ret;
45
46 #ifndef __USE_FILE_OFFSET64
47         ret = storage_get_internal_memory_size(&s);
48 #else
49         ret = storage_get_internal_memory_size64(&s);
50 #endif
51         if (ret < 0)
52                 return -EPERM;
53
54         if (total)
55                 *total = (unsigned long long)s.f_frsize*s.f_blocks;
56         if (available)
57                 *available = (unsigned long long)s.f_bsize*s.f_bavail;
58         return 0;
59 }
60
61 static const char *internal_get_root(void)
62 {
63         return tzplatform_getenv(TZ_USER_CONTENT);
64 }
65
66 const struct storage_ops internal = {
67         .type = STORAGE_TYPE_INTERNAL,
68         .root = internal_get_root,
69         .get_state = internal_get_state,
70         .get_space = internal_get_space,
71         .storage_id = 0,
72 };
73
74 STORAGE_OPS_REGISTER(&internal)