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 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 } 37 38 int WRAP(statfs)(const char* path, struct statfs_portable* stat) 39 { 40 struct statfs mips_stat; 41 int ret; 42 43 if (invalid_pointer(stat)) { 44 *REAL(__errno)() = EFAULT; 45 return -1; 46 } 47 ret = REAL(statfs)(path, &mips_stat); 48 statfs_ntop(&mips_stat, stat); 49 return ret; 50 } 51 52 int WRAP(fstatfs)(int fd, struct statfs_portable* stat) 53 { 54 struct statfs mips_stat; 55 int ret; 56 57 if (invalid_pointer(stat)) { 58 *REAL(__errno)() = EFAULT; 59 return -1; 60 } 61 ret = REAL(fstatfs)(fd, &mips_stat); 62 statfs_ntop(&mips_stat, stat); 63 return ret; 64 } 65