• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2014, 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 #ifndef _VFS_PORTABLE_H
18 #define _VFS_PORTABLE_H
19 
20 #include <stdlib.h>
21 #include <sys/vfs.h>
22 
23 /* The kernel's __kernel_fsid_t has a 'val' member but glibc uses '__val'. */
24 typedef struct { int __val[2]; } __fsid_t_portable;
25 typedef __fsid_t_portable fsid_t_portable;
26 
27 #define __STATFS64_BODY_PORTABLE \
28   uint64_t f_type; \
29   uint64_t f_bsize; \
30   uint64_t f_blocks; \
31   uint64_t f_bfree; \
32   uint64_t f_bavail; \
33   uint64_t f_files; \
34   uint64_t f_ffree; \
35   fsid_t_portable f_fsid; \
36   uint64_t f_namelen; \
37   uint64_t f_frsize; \
38   uint64_t f_flags; \
39   uint64_t f_spare[5]; \
40 
41 
42 struct statfs_portable { __STATFS64_BODY_PORTABLE };
43 struct statfs64_portable { __STATFS64_BODY_PORTABLE };
44 
45 static inline
statfs_ntop(struct statfs * n_statfs,struct statfs_portable * p_statfs)46 void statfs_ntop(struct statfs *n_statfs, struct statfs_portable *p_statfs) {
47   memset(p_statfs, 0, sizeof(struct statfs_portable));
48   p_statfs->f_type = n_statfs->f_type;
49   p_statfs->f_bsize = n_statfs->f_bsize;
50   p_statfs->f_blocks = n_statfs->f_blocks;
51   p_statfs->f_bfree = n_statfs->f_bfree;
52   p_statfs->f_bavail = n_statfs->f_bavail;
53   p_statfs->f_files = n_statfs->f_files;
54   p_statfs->f_ffree = n_statfs->f_ffree;
55   memcpy(&p_statfs->f_fsid, &n_statfs->f_fsid, sizeof(int)*2);
56   p_statfs->f_namelen = n_statfs->f_namelen;
57   p_statfs->f_frsize = n_statfs->f_frsize;
58   p_statfs->f_flags = n_statfs->f_flags;
59 #ifdef __mips__
60   memcpy(&p_statfs->f_spare, &n_statfs->f_spare, 4);
61 #else
62   memcpy(&p_statfs->f_spare, &n_statfs->f_spare, 5);
63 #endif
64 }
65 
66 
67 static inline
WRAP(statfs)68 int WRAP(statfs)(const char* path, struct statfs_portable* stat) {
69   struct statfs native_stat;
70 
71   int ret = REAL(statfs)(path, &native_stat);
72   statfs_ntop(&native_stat, stat);
73   return ret;
74 }
75 
76 static inline
WRAP(statfs64)77 int WRAP(statfs64)(const char* path, struct statfs64_portable* stat) {
78   return WRAP(statfs)(path, (struct statfs_portable*)stat);
79 }
80 
81 
82 static inline
WRAP(fstatfs)83 int WRAP(fstatfs)(int fd, struct statfs_portable* stat) {
84   struct statfs native_stat;
85 
86   int ret = REAL(fstatfs)(fd, &native_stat);
87   statfs_ntop(&native_stat, stat);
88   return ret;
89 }
90 
91 static inline
WRAP(fstatfs64)92 int WRAP(fstatfs64)(int fd, struct statfs64_portable* stat) {
93   return WRAP(fstatfs)(fd, (struct statfs_portable*)stat);
94 }
95 
96 #endif
97