root/branches/Orange-Branch/test/posix/libstat.c @ 8872

Revision 8872, 6.0 KB (checked in by mtmoore, 2 years ago)

compiler warning cleanup

Line 
1#include <stdio.h>
2#include <string.h>
3#include <sys/stat.h>
4#include <stdlib.h>
5#include <unistd.h>
6#include <linux/types.h>
7#include <assert.h>
8#include <linux/unistd.h>
9
10#define S_SLITE_SIZET     0x1
11#define S_SLITE_BLKSIZE   0x2
12#define S_SLITE_BLOCKS    0x4
13#define S_SLITE_ATIME     0x8
14#define S_SLITE_MTIME     0x10
15#define S_SLITE_CTIME     0x20
16#define S_SLITE_ALL       (S_SLITE_SIZET | S_SLITE_BLKSIZE | S_SLITE_BLOCKS \
17                                                                        S_SLITE_ATIME | S_SLITE_MTIME   | S_SLITE_CTIME)
18
19#define SLITE_SIZET(m)    ((m) & S_SLITE_SIZET)
20#define SLITE_BLKSIZE(m)  ((m) & S_SLITE_BLKSIZE)
21#define SLITE_BLOCKS(m)   ((m) & S_SLITE_BLOCKS)
22#define SLITE_ATIME(m)    ((m) & S_SLITE_ATIME)
23#define SLITE_MTIME(m)    ((m) & S_SLITE_MTIME)
24#define SLITE_CTIME(m)    ((m) & S_SLITE_CTIME)
25
26#if defined(__i386__) || defined(__i486__) || defined(__i586__) || defined(__i686__)
27/* FIXME:
28 * PLEASE CHANGE THIS SYSTEM
29 * CALL NUMBER IN CASE YOUR
30 * ARCHITECTURE IS NOT IA-32
31 * OR IF YOUR KERNEL SYSCALL NUMBERS
32 * ARE DIFFERENT. YOU HAVE BEEN WARNED!!!!!
33 */
34#define __NR_newstatlite 313
35#define __NR_newlstatlite 314
36#define __NR_newfstatlite 315
37
38struct kernel_stat_lite {
39        unsigned long  st_dev;
40        unsigned long  st_ino;
41        unsigned short st_mode;
42        unsigned short st_nlink;
43        unsigned short st_uid;
44        unsigned short st_gid;
45        unsigned long  st_rdev;
46        unsigned long  st_litemask;
47        unsigned long  st_size;
48        unsigned long  st_blksize;
49        unsigned long  st_blocks;
50        unsigned long  st_atim;
51        unsigned long  st_atime_nsec;
52        unsigned long  st_mtim;
53        unsigned long  st_mtime_nsec;
54        unsigned long  st_ctim;
55        unsigned long  st_ctime_nsec;
56        unsigned long  __unused4;
57        unsigned long  __unused5;
58};
59
60#elif defined (x86_64) || defined (__x86_64__)
61
62#define __NR_newstatlite   275
63#define __NR_newlstatlite  276
64#define __NR_newfstatlite  277
65
66struct kernel_stat_lite {
67        unsigned long   st_dev;
68        unsigned long   st_ino;
69        unsigned long   st_nlink;
70
71        unsigned int    st_mode;
72        unsigned int    st_uid;
73        unsigned int    st_gid;
74        unsigned int    __pad0;
75        unsigned long   st_rdev;
76        unsigned long  st_litemask;
77        long            st_size;
78        long            st_blksize;
79        long            st_blocks;      /* Number 512-byte blocks allocated. */
80
81        unsigned long   st_atim;
82        unsigned long   st_atime_nsec;
83        unsigned long   st_mtim;
84        unsigned long   st_mtime_nsec;
85        unsigned long   st_ctim;
86        unsigned long   st_ctime_nsec;
87        long            __unused[3];
88};
89#endif
90
91static int newstatlite(const char *, struct kernel_stat_lite *);
92static int newfstatlite(int, struct kernel_stat_lite *);
93static int newlstatlite(const char *, struct kernel_stat_lite *);
94static int getdents(uint, struct dirent *, uint);
95
96_syscall2(int, newstatlite, const char *, path, struct kernel_stat_lite *, buf);
97_syscall2(int, newfstatlite, int, filedes, struct kernel_stat_lite *, buf);
98_syscall2(int, newlstatlite, const char *, path, struct kernel_stat_lite *, buf);
99
100#if !defined(_FILE_OFFSET_BITS) && !defined(_LARGEFILE64_SOURCE)
101static void copy_statlite_to_stat(struct kernel_stat_lite *slbuf,
102                struct stat *sbuf)
103{
104        sbuf->st_dev = slbuf->st_dev;
105        sbuf->st_ino = slbuf->st_ino;
106        sbuf->st_mode = slbuf->st_mode;
107        sbuf->st_nlink = slbuf->st_nlink;
108        sbuf->st_uid = slbuf->st_uid;
109        sbuf->st_gid = slbuf->st_gid;
110        sbuf->st_rdev = slbuf->st_rdev;
111        sbuf->st_size = 0;
112        sbuf->st_blksize = slbuf->st_blksize;
113        sbuf->st_blocks = slbuf->st_blocks;
114        sbuf->st_atime = slbuf->st_atim;
115        sbuf->st_mtime = slbuf->st_mtim;
116        sbuf->st_ctime = slbuf->st_ctim;
117}
118
119int __xstat(int vers, const char *pathname, struct stat *sbuf)
120{
121        struct kernel_stat_lite slbuf;
122        int ret;
123        memset(&slbuf, 0, sizeof(slbuf));
124        slbuf.st_litemask = S_SLITE_ATIME |
125                S_SLITE_MTIME |
126                S_SLITE_CTIME |
127                S_SLITE_BLKSIZE |
128                S_SLITE_BLOCKS;
129        ret = newstatlite(pathname, &slbuf);
130        if (ret < 0)
131                return ret;
132        copy_statlite_to_stat(&slbuf, sbuf);
133        return 0;
134}
135
136int __lxstat(int vers, const char *pathname, struct stat *sbuf)
137{
138        struct kernel_stat_lite slbuf;
139        int ret;
140        memset(&slbuf, 0, sizeof(slbuf));
141        slbuf.st_litemask = S_SLITE_ATIME |
142                S_SLITE_MTIME |
143                S_SLITE_CTIME |
144                S_SLITE_BLKSIZE |
145                S_SLITE_BLOCKS;
146        ret = newlstatlite(pathname, &slbuf);
147        if (ret < 0)
148                return ret;
149        copy_statlite_to_stat(&slbuf, sbuf);
150        return 0;
151}
152
153int __fxstat(int vers, int fd, struct stat *sbuf)
154{
155        struct kernel_stat_lite slbuf;
156        int ret;
157        memset(&slbuf, 0, sizeof(slbuf));
158        slbuf.st_litemask = S_SLITE_ATIME |
159                S_SLITE_MTIME |
160                S_SLITE_CTIME |
161                S_SLITE_BLKSIZE |
162                S_SLITE_BLOCKS;
163        ret = newfstatlite(fd, &slbuf);
164        if (ret < 0)
165                return ret;
166        copy_statlite_to_stat(&slbuf, sbuf);
167        return 0;
168}
169#else
170static void copy_statlite_to_stat64(struct kernel_stat_lite *slbuf,
171                struct stat64 *sbuf)
172{
173        sbuf->st_dev = slbuf->st_dev;
174        sbuf->st_ino = slbuf->st_ino;
175        sbuf->st_mode = slbuf->st_mode;
176        sbuf->st_nlink = slbuf->st_nlink;
177        sbuf->st_uid = slbuf->st_uid;
178        sbuf->st_gid = slbuf->st_gid;
179        sbuf->st_rdev = slbuf->st_rdev;
180        sbuf->st_size = 0;
181        sbuf->st_blksize = slbuf->st_blksize;
182        sbuf->st_blocks = slbuf->st_blocks;
183        sbuf->st_atime = slbuf->st_atim;
184        sbuf->st_mtime = slbuf->st_mtim;
185        sbuf->st_ctime = slbuf->st_ctim;
186}
187
188int __xstat64(int vers, const char *pathname, struct stat64 *sbuf)
189{
190        struct kernel_stat_lite slbuf;
191        int ret;
192
193        memset(&slbuf, 0, sizeof(slbuf));
194        slbuf.st_litemask = S_SLITE_ATIME |
195                S_SLITE_MTIME |
196                S_SLITE_CTIME |
197                S_SLITE_BLKSIZE |
198                S_SLITE_BLOCKS;
199        ret = newstatlite(pathname, &slbuf);
200        if (ret < 0)
201                return ret;
202        copy_statlite_to_stat64(&slbuf, sbuf);
203        return 0;
204}
205
206int __lxstat64(int vers, const char *pathname, struct stat64 *sbuf)
207{
208        struct kernel_stat_lite slbuf;
209        int ret;
210
211        memset(&slbuf, 0, sizeof(slbuf));
212        slbuf.st_litemask = S_SLITE_ATIME |
213                S_SLITE_MTIME |
214                S_SLITE_CTIME |
215                S_SLITE_BLKSIZE |
216                S_SLITE_BLOCKS;
217        ret = newlstatlite(pathname, &slbuf);
218        if (ret < 0)
219                return ret;
220        copy_statlite_to_stat64(&slbuf, sbuf);
221        return 0;
222}
223
224int __fxstat64(int vers, int fd, struct stat64 *sbuf)
225{
226        struct kernel_stat_lite slbuf;
227        int ret;
228
229        memset(&slbuf, 0, sizeof(slbuf));
230        slbuf.st_litemask = S_SLITE_ATIME |
231                S_SLITE_MTIME |
232                S_SLITE_CTIME |
233                S_SLITE_BLKSIZE |
234                S_SLITE_BLOCKS;
235        ret = newfstatlite(fd, &slbuf);
236        if (ret < 0)
237                return ret;
238        copy_statlite_to_stat64(&slbuf, sbuf);
239        return 0;
240}
241#endif
Note: See TracBrowser for help on using the browser.