blob: fb9671de8bf2ad3d358ab0109a6b4b6d2bb2eb75 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
/*
* Copyright 2012, The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef _STAT_PORTABLE_H_
#define _STAT_PORTABLE_H_
#include <sys/stat.h>
#include <string.h>
#ifdef __LP64__
#define __STAT64_BODY_PORTABLE \
unsigned long st_dev; \
unsigned long st_ino; \
unsigned int st_mode; \
unsigned int st_nlink; \
uid_t st_uid; \
gid_t st_gid; \
unsigned long st_rdev; \
unsigned long __pad1; \
long st_size; \
int st_blksize; \
int __pad2; \
long st_blocks; \
long st_atime; \
unsigned long st_atime_nsec; \
long st_mtime; \
unsigned long st_mtime_nsec; \
long st_ctime; \
unsigned long st_ctime_nsec; \
unsigned int __unused4; \
unsigned int __unused5; \
unsigned long __unused_for_largest_size; \
struct stat_portable { __STAT64_BODY_PORTABLE };
struct stat64_portable { __STAT64_BODY_PORTABLE };
static inline
void stat_ntop(struct stat *n_stat, struct stat_portable *p_stat)
{
memset(p_stat, '\0', sizeof(struct stat_portable));
p_stat->st_dev = n_stat->st_dev;
p_stat->st_ino = n_stat->st_ino;
p_stat->st_mode = n_stat->st_mode;
p_stat->st_nlink = n_stat->st_nlink;
p_stat->st_uid = n_stat->st_uid;
p_stat->st_gid = n_stat->st_gid;
p_stat->st_rdev = n_stat->st_rdev;
p_stat->st_size = n_stat->st_size;
p_stat->st_blksize = n_stat->st_blksize;
p_stat->st_blocks = n_stat->st_blocks;
p_stat->st_atime = n_stat->st_atime;
p_stat->st_atime_nsec = n_stat->st_atime_nsec;
p_stat->st_mtime = n_stat->st_mtime;
p_stat->st_mtime_nsec = n_stat->st_mtime_nsec;
p_stat->st_ctime = n_stat->st_ctime;
p_stat->st_ctime_nsec = n_stat->st_ctime_nsec;
}
#else // ! __LP64__
/* It's easy to change kernel to support stat */
struct stat_portable {
unsigned long long st_dev;
unsigned char __pad0[4];
unsigned long __st_ino;
unsigned int st_mode;
unsigned int st_nlink;
unsigned long st_uid;
unsigned long st_gid;
unsigned long long st_rdev;
unsigned char __pad3[4];
unsigned char __pad4[4];
long long st_size;
unsigned long st_blksize;
unsigned char __pad5[4];
unsigned long long st_blocks;
unsigned long st_atime;
unsigned long st_atime_nsec;
unsigned long st_mtime;
unsigned long st_mtime_nsec;
unsigned long st_ctime;
unsigned long st_ctime_nsec;
unsigned long long st_ino;
};
/*
The X86 Version is
struct stat {
unsigned long long st_dev;
unsigned char __pad0[4];
unsigned long __st_ino;
unsigned int st_mode;
unsigned int st_nlink;
unsigned long st_uid;
unsigned long st_gid;
unsigned long long st_rdev;
unsigned char __pad3[4];
long long st_size;
unsigned long st_blksize;
unsigned long long st_blocks;
unsigned long st_atime;
unsigned long st_atime_nsec;
unsigned long st_mtime;
unsigned long st_mtime_nsec;
unsigned long st_ctime;
unsigned long st_ctime_nsec;
unsigned long long st_ino;
};
*/
/*
The MIPS Version is
struct stat {
unsigned long st_dev;
unsigned long __pad0[3];
unsigned long long st_ino;
unsigned int st_mode;
unsigned int st_nlink;
unsigned long st_uid;
unsigned long st_gid;
unsigned long st_rdev;
unsigned long __pad1[3];
long long st_size;
unsigned long st_atime;
unsigned long st_atime_nsec;
unsigned long st_mtime;
unsigned long st_mtime_nsec;
unsigned long st_ctime;
unsigned long st_ctime_nsec;
unsigned long st_blksize;
unsigned long __pad2;
unsigned long long st_blocks;
};
*/
static inline void stat_ntop(struct stat *n_stat, struct stat_portable *p_stat)
{
memset(p_stat, '\0', sizeof(struct stat_portable));
p_stat->st_dev = n_stat->st_dev;
#if defined(__mips__)
/* MIPS doesn't have __st_ino */
p_stat->__st_ino = 0;
#else
p_stat->__st_ino = n_stat->__st_ino;
#endif
p_stat->st_mode = n_stat->st_mode;
p_stat->st_nlink = n_stat->st_nlink;
p_stat->st_uid = n_stat->st_uid;
p_stat->st_gid = n_stat->st_gid;
p_stat->st_rdev = n_stat->st_rdev;
p_stat->st_size = n_stat->st_size;
p_stat->st_blksize = n_stat->st_blksize;
p_stat->st_blocks = n_stat->st_blocks;
p_stat->st_atime = n_stat->st_atime;
p_stat->st_atime_nsec = n_stat->st_atime_nsec;
p_stat->st_mtime = n_stat->st_mtime;
p_stat->st_mtime_nsec = n_stat->st_mtime_nsec;
p_stat->st_ctime = n_stat->st_ctime;
p_stat->st_ctime_nsec = n_stat->st_ctime_nsec;
p_stat->st_ino = n_stat->st_ino;
}
#endif // __LP64__
#endif /* _STAT_PORTABLE_H */
|