1/*	$NetBSD: compat.c,v 1.8 2011/01/04 17:00:19 pooka Exp $	*/
2
3/*
4 * Copyright (c) 2009 Antti Kantee.  All Rights Reserved.
5 *
6 * Development of this software was supported by the Nokia Foundation
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
18 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30#include <sys/cdefs.h>
31__KERNEL_RCSID(0, "$NetBSD: compat.c,v 1.8 2011/01/04 17:00:19 pooka Exp $");
32
33#include <sys/param.h>
34#include <sys/kmem.h>
35#include <sys/sched.h>
36#include <sys/syscallargs.h>
37#include <sys/vnode.h>
38
39#include <compat/sys/time.h>
40
41#include <rump/rump.h>
42#include <rump/rump_syscalls_compat.h>
43#include <rump/rumpuser.h>
44
45#include "rump_vfs_private.h"
46
47/*
48 * XXX: these are handwritten for now.  They provide compat for
49 * calling post-time_t file systems from a pre-time_t userland.
50 * (mknod is missing.  I don't care very much)
51 *
52 * Doing remote system calls with these does not (obviously) work.
53 */
54#if     BYTE_ORDER == BIG_ENDIAN
55#define SPARG(p,k)      ((p)->k.be.datum)
56#else /* LITTLE_ENDIAN, I hope dearly */
57#define SPARG(p,k)      ((p)->k.le.datum)
58#endif
59
60struct vattr50 {
61	enum vtype	va_type;	/* vnode type (for create) */
62	mode_t		va_mode;	/* files access mode and type */
63	nlink_t		va_nlink;	/* number of references to file */
64	uid_t		va_uid;		/* owner user id */
65	gid_t		va_gid;		/* owner group id */
66	u_long		va_fsid;	/* file system id (dev for now) */
67	ino_t		va_fileid;	/* file id */
68	u_quad_t	va_size;	/* file size in bytes */
69	long		va_blocksize;	/* blocksize preferred for i/o */
70	struct timespec50 va_atime;	/* time of last access */
71	struct timespec50 va_mtime;	/* time of last modification */
72	struct timespec50 va_ctime;	/* time file changed */
73	struct timespec50 va_birthtime;	/* time file created */
74	u_long		va_gen;		/* generation number of file */
75	u_long		va_flags;	/* flags defined for file */
76	uint32_t	va_rdev;	/* device the special file represents */
77	u_quad_t	va_bytes;	/* bytes of disk space held by file */
78	u_quad_t	va_filerev;	/* file modification number */
79	u_int		va_vaflags;	/* operations flags, see below */
80	long		va_spare;	/* remain quad aligned */
81};
82
83/*
84 * XXX: types.  But I don't want to start playing compat games in
85 * the userspace namespace too
86 */
87void
88rump_vattr50_to_vattr(const struct vattr *_va50, struct vattr *va)
89{
90	const struct vattr50 *va50 = (const struct vattr50 *)_va50;
91
92	va->va_type = va50->va_type;
93	va->va_mode = va50->va_mode;
94	va->va_nlink = va50->va_nlink;
95	va->va_uid = va50->va_uid;
96	va->va_gid = va50->va_gid;
97	va->va_fsid = (long)va50->va_fsid;
98	va->va_fileid = va50->va_fileid;
99	va->va_size = va50->va_size;
100	va->va_blocksize = va50->va_blocksize;
101	timespec50_to_timespec(&va50->va_atime, &va->va_atime);
102	timespec50_to_timespec(&va50->va_ctime, &va->va_ctime);
103	timespec50_to_timespec(&va50->va_mtime, &va->va_mtime);
104	timespec50_to_timespec(&va50->va_birthtime, &va->va_birthtime);
105	va->va_gen = va50->va_gen;
106	va->va_flags = va50->va_flags;
107	va->va_rdev = (int32_t)va50->va_rdev;
108	va->va_bytes = va50->va_bytes;
109	va->va_filerev = va50->va_filerev;
110	va->va_vaflags = va50->va_flags;
111}
112
113void
114rump_vattr_to_vattr50(const struct vattr *va, struct vattr *_va50)
115{
116	struct vattr50 *va50 = (struct vattr50 *)_va50;
117
118	va50->va_type = va->va_type;
119	va50->va_mode = va->va_mode;
120	va50->va_nlink = va->va_nlink;
121	va50->va_uid = va->va_uid;
122	va50->va_gid = va->va_gid;
123	va50->va_fsid = (u_long)va->va_fsid;
124	va50->va_fileid = va->va_fileid;
125	va50->va_size = va->va_size;
126	va50->va_blocksize = va->va_blocksize;
127	timespec_to_timespec50(&va->va_atime, &va50->va_atime);
128	timespec_to_timespec50(&va->va_ctime, &va50->va_ctime);
129	timespec_to_timespec50(&va->va_mtime, &va50->va_mtime);
130	timespec_to_timespec50(&va->va_birthtime, &va50->va_birthtime);
131	va50->va_gen = va->va_gen;
132	va50->va_flags = va->va_flags;
133	va50->va_rdev = (uint32_t)va->va_rdev;
134	va50->va_bytes = va->va_bytes;
135	va50->va_filerev = va->va_filerev;
136	va50->va_vaflags = va->va_flags;
137}
138