Deleted Added
sdiff udiff text old ( 10358 ) new ( 12458 )
full compact
1/*-
2 * Copyright (c) 1994-1995 S�ren Schmidt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software withough specific prior written permission
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $Id: linux_stats.c,v 1.1 1995/06/25 17:32:42 sos Exp $
29 */
30
31#include <sys/param.h>
32#include <sys/systm.h>
33#include <sys/dirent.h>
34#include <sys/file.h>
35#include <sys/filedesc.h>
36#include <sys/proc.h>
37#include <sys/mount.h>
38#include <sys/namei.h>
39#include <sys/stat.h>
40#include <sys/vnode.h>
41
42#include <machine/cpu.h>
43#include <machine/psl.h>
44#include <machine/reg.h>
45
46#include <i386/linux/linux.h>
47
48struct linux_newstat {
49 unsigned short stat_dev;
50 unsigned short __pad1;
51 unsigned long stat_ino;
52 unsigned short stat_mode;
53 unsigned short stat_nlink;
54 unsigned short stat_uid;
55 unsigned short stat_gid;
56 unsigned short stat_rdev;
57 unsigned short __pad2;
58 unsigned long stat_size;
59 unsigned long stat_blksize;
60 unsigned long stat_blocks;
61 unsigned long stat_atime;
62 unsigned long __unused1;
63 unsigned long stat_mtime;
64 unsigned long __unused2;
65 unsigned long stat_ctime;
66 unsigned long __unused3;
67 unsigned long __unused4;
68 unsigned long __unused5;
69};
70
71struct linux_newstat_args {
72 char *path;
73 struct linux_newstat *buf;
74};
75
76static int
77newstat_copyout(struct stat *buf, void *ubuf)
78{
79 struct linux_newstat tbuf;
80
81 tbuf.stat_dev = (buf->st_dev & 0xff) | ((buf->st_dev & 0xff00)<<10);
82 tbuf.stat_ino = buf->st_ino;
83 tbuf.stat_mode = buf->st_mode;
84 tbuf.stat_nlink = buf->st_nlink;
85 tbuf.stat_uid = buf->st_uid;
86 tbuf.stat_gid = buf->st_gid;
87 tbuf.stat_rdev = buf->st_rdev;
88 tbuf.stat_size = buf->st_size;
89 tbuf.stat_atime = buf->st_atime;
90 tbuf.stat_mtime = buf->st_mtime;
91 tbuf.stat_ctime = buf->st_ctime;
92 tbuf.stat_blksize = buf->st_blksize;
93 tbuf.stat_blocks = buf->st_blocks;
94 return copyout(&tbuf, ubuf, sizeof(tbuf));
95}
96
97int
98linux_newstat(struct proc *p, struct linux_newstat_args *args, int *retval)
99{
100 struct stat buf;
101 struct linux_newstat tbuf;
102 struct nameidata nd;
103 int error;
104
105#ifdef DEBUG
106 printf("Linux-emul(%d): newstat(%s, *)\n", p->p_pid, args->path);
107#endif
108 NDINIT(&nd, LOOKUP, LOCKLEAF|FOLLOW, UIO_USERSPACE, args->path, p);
109 error = namei(&nd);
110 if (!error) {
111 error = vn_stat(nd.ni_vp, &buf, p);
112 vput(nd.ni_vp);
113 }
114 if (!error)
115 error = newstat_copyout(&buf, args->buf);
116 return error;
117}
118
119int
120linux_newlstat(struct proc *p, struct linux_newstat_args *args, int *retval)
121{
122 struct stat buf;
123 struct linux_newstat tbuf;
124 struct nameidata nd;
125 int error;
126
127#ifdef DEBUG
128 printf("Linux-emul(%d): newlstat(%s, *)\n", p->p_pid, args->path);
129#endif
130 NDINIT(&nd, LOOKUP, LOCKLEAF|FOLLOW, UIO_USERSPACE, args->path, p);
131 error = namei(&nd);
132 if (!error) {
133 error = vn_stat(nd.ni_vp, &buf, p);
134 vput(nd.ni_vp);
135 }
136 if (!error)
137 error = newstat_copyout(&buf, args->buf);
138 return error;
139}
140
141struct linux_newfstat_args {
142 int fd;
143 struct linux_newstat *buf;
144};
145
146int
147linux_newfstat(struct proc *p, struct linux_newfstat_args *args, int *retval)
148{
149 struct linux_newstat tbuf;
150 struct filedesc *fdp = p->p_fd;
151 struct file *fp;
152 struct stat buf;
153 int error;
154
155#ifdef DEBUG
156 printf("Linux-emul(%d): newlstat(%d, *)\n", p->p_pid, args->fd);
157#endif
158 if ((unsigned)args->fd >= fdp->fd_nfiles
159 || (fp = fdp->fd_ofiles[args->fd]) == NULL)
160 return EBADF;
161 switch (fp->f_type) {
162 case DTYPE_VNODE:
163 error = vn_stat((struct vnode *)fp->f_data, &buf, p);
164 break;
165 case DTYPE_SOCKET:
166 error = soo_stat((struct socket *)fp->f_data, &buf);
167 break;
168 default:
169 panic("LINUX newfstat");
170 }
171 if (!error)
172 error = newstat_copyout(&buf, args->buf);
173 return error;
174}
175
176struct linux_statfs {
177 long ftype;
178 long fbsize;
179 long fblocks;
180 long fbfree;
181 long fbavail;
182 long ffiles;
183 long fffree;
184 linux_fsid_t ffsid;
185 long fnamelen;
186 long fspare[6];
187};
188
189
190struct linux_statfs_args {
191 char *path;
192 struct statfs *buf;
193};
194
195int
196linux_statfs(struct proc *p, struct linux_statfs_args *args, int *retval)
197{
198 struct mount *mp;
199 struct nameidata *ndp;
200 struct statfs *bsd_statfs;
201 struct nameidata nd;
202 struct linux_statfs linux_statfs;
203 int error;
204
205#ifdef DEBUG
206 printf("Linux-emul(%d): statfs(%s, *)\n", p->p_pid, args->path);
207#endif
208 ndp = &nd;
209 NDINIT(ndp, LOOKUP, FOLLOW, UIO_USERSPACE, args->path, curproc);
210 if (error = namei(ndp))
211 return error;
212 mp = ndp->ni_vp->v_mount;
213 bsd_statfs = &mp->mnt_stat;
214 vrele(ndp->ni_vp);
215 if (error = VFS_STATFS(mp, bsd_statfs, p))
216 return error;
217 bsd_statfs->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
218 linux_statfs.ftype = bsd_statfs->f_type;
219 linux_statfs.fbsize = bsd_statfs->f_bsize;
220 linux_statfs.fblocks = bsd_statfs->f_blocks;
221 linux_statfs.fbfree = bsd_statfs->f_bfree;
222 linux_statfs.fbavail = bsd_statfs->f_bavail;
223 linux_statfs.fffree = bsd_statfs->f_ffree;
224 linux_statfs.ffiles = bsd_statfs->f_files;
225 linux_statfs.ffsid.val[0] = bsd_statfs->f_fsid.val[0];
226 linux_statfs.ffsid.val[1] = bsd_statfs->f_fsid.val[1];
227 linux_statfs.fnamelen = MAXNAMLEN;
228 return copyout((caddr_t)&linux_statfs, (caddr_t)args->buf,
229 sizeof(struct linux_statfs));
230}
231
232struct linux_fstatfs_args {
233 int fd;
234 struct statfs *buf;
235};
236
237int
238linux_fstatfs(struct proc *p, struct linux_fstatfs_args *args, int *retval)
239{
240 struct file *fp;
241 struct mount *mp;
242 struct statfs *bsd_statfs;
243 struct linux_statfs linux_statfs;
244 int error;
245
246#ifdef DEBUG
247 printf("Linux-emul(%d): fstatfs(%d, *)\n", p->p_pid, args->fd);
248#endif
249 if (error = getvnode(p->p_fd, args->fd, &fp))
250 return error;
251 mp = ((struct vnode *)fp->f_data)->v_mount;
252 bsd_statfs = &mp->mnt_stat;
253 if (error = VFS_STATFS(mp, bsd_statfs, p))
254 return error;
255 bsd_statfs->f_flags = mp->mnt_flag & MNT_VISFLAGMASK;
256 linux_statfs.ftype = bsd_statfs->f_type;
257 linux_statfs.fbsize = bsd_statfs->f_bsize;
258 linux_statfs.fblocks = bsd_statfs->f_blocks;
259 linux_statfs.fbfree = bsd_statfs->f_bfree;
260 linux_statfs.fbavail = bsd_statfs->f_bavail;
261 linux_statfs.fffree = bsd_statfs->f_ffree;
262 linux_statfs.ffiles = bsd_statfs->f_files;
263 linux_statfs.ffsid.val[0] = bsd_statfs->f_fsid.val[0];
264 linux_statfs.ffsid.val[1] = bsd_statfs->f_fsid.val[1];
265 linux_statfs.fnamelen = MAXNAMLEN;
266 return copyout((caddr_t)&linux_statfs, (caddr_t)args->buf,
267 sizeof(struct linux_statfs));
268}