• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2012, The Android Open Source Project
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 #include <portability.h>
18 #include <string.h>
19 #include <errno.h>
20 #include <errno_portable.h>
21 #include <statfs_portable.h>
22 
statfs_ntop(struct statfs * n_statfs,struct statfs_portable * p_statfs)23 static inline void statfs_ntop(struct statfs *n_statfs, struct statfs_portable *p_statfs)
24 {
25     memset(p_statfs, '\0', sizeof(struct statfs_portable));
26     p_statfs->f_type = n_statfs->f_type;
27     p_statfs->f_bsize = n_statfs->f_bsize;
28     p_statfs->f_blocks = n_statfs->f_blocks;
29     p_statfs->f_bfree = n_statfs->f_bfree;
30     p_statfs->f_bavail = n_statfs->f_bavail;
31     p_statfs->f_files = n_statfs->f_files;
32     p_statfs->f_ffree = n_statfs->f_ffree;
33     p_statfs->f_fsid = n_statfs->f_fsid;
34     p_statfs->f_namelen = n_statfs->f_namelen;
35     p_statfs->f_frsize = n_statfs->f_frsize;
36     p_statfs->f_flags = n_statfs->f_flags;
37 }
38 
WRAP(statfs)39 int WRAP(statfs)(const char*  path, struct statfs_portable*  stat)
40 {
41     struct statfs mips_stat;
42     int ret;
43 
44     if (invalid_pointer(stat)) {
45         *REAL(__errno)() = EFAULT;
46         return -1;
47     }
48     ret = REAL(statfs)(path, &mips_stat);
49     statfs_ntop(&mips_stat, stat);
50     return ret;
51 }
52 
WRAP(fstatfs)53 int WRAP(fstatfs)(int fd, struct statfs_portable*  stat)
54 {
55     struct statfs mips_stat;
56     int ret;
57 
58     if (invalid_pointer(stat)) {
59         *REAL(__errno)() = EFAULT;
60         return -1;
61     }
62     ret = REAL(fstatfs)(fd, &mips_stat);
63     statfs_ntop(&mips_stat, stat);
64     return ret;
65 }
66