Home | History | Annotate | Download | only in include
      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 #ifndef _STAT_PORTABLE_H_
     18 #define _STAT_PORTABLE_H_
     19 
     20 #include <sys/stat.h>
     21 #include <string.h>
     22 
     23 /* It's easy to change kernel to support stat */
     24 struct stat_portable {
     25     unsigned long long  st_dev;
     26     unsigned char       __pad0[4];
     27 
     28     unsigned long       __st_ino;
     29     unsigned int        st_mode;
     30     unsigned int        st_nlink;
     31 
     32     unsigned long       st_uid;
     33     unsigned long       st_gid;
     34 
     35     unsigned long long  st_rdev;
     36     unsigned char       __pad3[4];
     37 
     38     unsigned char       __pad4[4];
     39     long long           st_size;
     40     unsigned long       st_blksize;
     41     unsigned char       __pad5[4];
     42     unsigned long long  st_blocks;
     43 
     44     unsigned long       st_atime;
     45     unsigned long       st_atime_nsec;
     46 
     47     unsigned long       st_mtime;
     48     unsigned long       st_mtime_nsec;
     49 
     50     unsigned long       st_ctime;
     51     unsigned long       st_ctime_nsec;
     52 
     53     unsigned long long  st_ino;
     54 };
     55 
     56 /*
     57 The X86 Version is
     58 struct stat {
     59     unsigned long long  st_dev;
     60     unsigned char       __pad0[4];
     61 
     62     unsigned long       __st_ino;
     63     unsigned int        st_mode;
     64     unsigned int        st_nlink;
     65 
     66     unsigned long       st_uid;
     67     unsigned long       st_gid;
     68 
     69     unsigned long long  st_rdev;
     70     unsigned char       __pad3[4];
     71 
     72     long long           st_size;
     73     unsigned long       st_blksize;
     74     unsigned long long  st_blocks;
     75 
     76     unsigned long       st_atime;
     77     unsigned long       st_atime_nsec;
     78 
     79     unsigned long       st_mtime;
     80     unsigned long       st_mtime_nsec;
     81 
     82     unsigned long       st_ctime;
     83     unsigned long       st_ctime_nsec;
     84 
     85     unsigned long long  st_ino;
     86 };
     87 */
     88 
     89 /*
     90 The MIPS Version is
     91 struct stat {
     92     unsigned long       st_dev;
     93     unsigned long       __pad0[3];
     94 
     95     unsigned long long  st_ino;
     96 
     97     unsigned int        st_mode;
     98     unsigned int        st_nlink;
     99 
    100     unsigned long       st_uid;
    101     unsigned long       st_gid;
    102 
    103     unsigned long       st_rdev;
    104     unsigned long       __pad1[3];
    105 
    106     long long           st_size;
    107 
    108     unsigned long       st_atime;
    109     unsigned long       st_atime_nsec;
    110 
    111     unsigned long       st_mtime;
    112     unsigned long       st_mtime_nsec;
    113 
    114     unsigned long       st_ctime;
    115     unsigned long       st_ctime_nsec;
    116 
    117     unsigned long       st_blksize;
    118     unsigned long       __pad2;
    119 
    120     unsigned long long  st_blocks;
    121 };
    122 */
    123 
    124 static inline void stat_ntop(struct stat *n_stat, struct stat_portable *p_stat)
    125 {
    126     memset(p_stat, '\0', sizeof(struct stat_portable));
    127     p_stat->st_dev        = n_stat->st_dev;
    128 #if defined(__mips__)
    129     /* MIPS doesn't have __st_ino */
    130     p_stat->__st_ino      = 0;
    131 #else
    132     p_stat->__st_ino      = n_stat->__st_ino;
    133 #endif
    134     p_stat->st_mode       = n_stat->st_mode;
    135     p_stat->st_nlink      = n_stat->st_nlink;
    136     p_stat->st_uid        = n_stat->st_uid;
    137     p_stat->st_gid        = n_stat->st_gid;
    138     p_stat->st_rdev       = n_stat->st_rdev;
    139     p_stat->st_size       = n_stat->st_size;
    140     p_stat->st_blksize    = n_stat->st_blksize;
    141     p_stat->st_blocks     = n_stat->st_blocks;
    142     p_stat->st_atime      = n_stat->st_atime;
    143     p_stat->st_atime_nsec = n_stat->st_atime_nsec;
    144     p_stat->st_mtime      = n_stat->st_mtime;
    145     p_stat->st_mtime_nsec = n_stat->st_mtime_nsec;
    146     p_stat->st_ctime      = n_stat->st_ctime;
    147     p_stat->st_ctime_nsec = n_stat->st_ctime_nsec;
    148     p_stat->st_ino        = n_stat->st_ino;
    149 }
    150 
    151 #endif /* _STAT_PORTABLE_H */
    152