Apply requirement for gcov automation
[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 <unistd.h>
19 #include <sys/types.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <string.h>
23 #include <errno.h>
24 #include <limits.h>
25 #include <sys/statvfs.h>
26 #include <tzplatform_config.h>
27 #include <libmount.h>
28
29 #include "common.h"
30 #include "log.h"
31
32 #ifdef __USE_FILE_OFFSET64
33 int __WEAK__ storage_get_internal_memory_size64(struct statvfs *buf);
34 #else
35 int __WEAK__ storage_get_internal_memory_size(struct statvfs *buf);
36 #endif
37
38 static int internal_get_state(void)
39 {
40         return STORAGE_STATE_MOUNTED;
41 }
42
43 static int internal_get_space(unsigned long long *total, unsigned long long *available)
44 {
45         struct statvfs s;
46         int ret_val;
47
48 #ifdef __USE_FILE_OFFSET64
49         ret_val = storage_get_internal_memory_size64(&s);
50 #else
51         ret_val = storage_get_internal_memory_size(&s);
52 #endif
53         if (ret_val < 0)
54                 return -EPERM;
55
56         if (total)
57                 *total = (unsigned long long)s.f_frsize*s.f_blocks;
58         if (available)
59                 *available = (unsigned long long)s.f_bsize*s.f_bavail;
60         return 0;
61 }
62
63 static const char *internal_get_root(void)
64 {
65         const char *ret;
66         ret = tzplatform_uid_getenv(getuid(), TZ_USER_CONTENT);
67
68         return ret;
69 }
70
71 const struct storage_ops internal = {
72         .type = STORAGE_TYPE_INTERNAL,
73         .root = internal_get_root,
74         .get_state = internal_get_state,
75         .get_space = internal_get_space,
76         .storage_id = 0,
77 };
78
79 STORAGE_OPS_REGISTER(&internal)