• 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 <portability.h>
21 #include <stdint.h>
22 #include <stdlib.h>
23 #include <sys/vfs.h>
24 
25 typedef __fsid_t fsid_t;
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 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 StatfsPortable { __STATFS64_BODY_PORTABLE };
43 typedef struct StatfsPortable Statfs64Portable;
44 
45 #undef __STATFS64_BODY_PORTABLE
46 
statfs_n2p(const struct statfs * pn,struct StatfsPortable * pp)47 static void statfs_n2p(const struct statfs* pn, struct StatfsPortable* pp)
48 {
49   memset(pp, '\0', sizeof(struct StatfsPortable));
50   pp->f_type    = pn->f_type;
51   pp->f_bsize   = pn->f_bsize;
52   pp->f_blocks  = pn->f_blocks;
53   pp->f_bfree   = pn->f_bfree;
54   pp->f_bavail  = pn->f_bavail;
55   pp->f_files   = pn->f_files;
56   pp->f_ffree   = pn->f_ffree;
57   memcpy(&pp->f_fsid, &pn->f_fsid, sizeof(int)*2);
58   pp->f_namelen = pn->f_namelen;
59   pp->f_frsize  = pn->f_frsize;
60   pp->f_flags   = pn->f_flags;
61 #ifdef __mips__
62   memcpy(&pp->f_spare, &pn->f_spare, 4);
63 #else
64   memcpy(&pp->f_spare, &pn->f_spare, 5);
65 #endif
66 }
67 
WRAP(statfs)68 int WRAP(statfs)(const char* path, struct StatfsPortable* stat)
69 {
70   struct statfs target_stat;
71   int ret = REAL(statfs)(path, &target_stat);
72   statfs_n2p(&target_stat, stat);
73   return ret;
74 }
75 
WRAP(statfs64)76 int WRAP(statfs64)(const char* path, Statfs64Portable* stat)
77 {
78   return WRAP(statfs)(path, stat);
79 }
80 
WRAP(fstatfs)81 int WRAP(fstatfs)(int fd, struct StatfsPortable* stat)
82 {
83   struct statfs target_stat;
84   int ret = REAL(fstatfs)(fd, &target_stat);
85   statfs_n2p(&target_stat, stat);
86   return ret;
87 }
88 
WRAP(fstatfs64)89 int WRAP(fstatfs64)(int fd, Statfs64Portable* stat)
90 {
91   return WRAP(fstatfs)(fd, stat);
92 }
93 
94 #endif /* _VFS_PORTABLE_H */
95