1 /* $NetBSD: rumpvfs_compat50.c,v 1.2 2016/01/26 23:12:18 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: rumpvfs_compat50.c,v 1.2 2016/01/26 23:12:18 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-sys/vfs.h> 42 43 #include <rump/rump.h> 44 45 /* 46 * XXX: these are handwritten for now. They provide compat for 47 * calling post-time_t file systems from a pre-time_t userland. 48 * (mknod is missing. I don't care very much) 49 * 50 * Doing remote system calls with these does not (obviously) work. 51 */ 52 #if BYTE_ORDER == BIG_ENDIAN 53 #define SPARG(p,k) ((p)->k.be.datum) 54 #else /* LITTLE_ENDIAN, I hope dearly */ 55 #define SPARG(p,k) ((p)->k.le.datum) 56 #endif 57 58 struct vattr50 { 59 enum vtype va_type; /* vnode type (for create) */ 60 mode_t va_mode; /* files access mode and type */ 61 nlink_t va_nlink; /* number of references to file */ 62 uid_t va_uid; /* owner user id */ 63 gid_t va_gid; /* owner group id */ 64 u_long va_fsid; /* file system id (dev for now) */ 65 ino_t va_fileid; /* file id */ 66 u_quad_t va_size; /* file size in bytes */ 67 long va_blocksize; /* blocksize preferred for i/o */ 68 struct timespec50 va_atime; /* time of last access */ 69 struct timespec50 va_mtime; /* time of last modification */ 70 struct timespec50 va_ctime; /* time file changed */ 71 struct timespec50 va_birthtime; /* time file created */ 72 u_long va_gen; /* generation number of file */ 73 u_long va_flags; /* flags defined for file */ 74 uint32_t va_rdev; /* device the special file represents */ 75 u_quad_t va_bytes; /* bytes of disk space held by file */ 76 u_quad_t va_filerev; /* file modification number */ 77 u_int va_vaflags; /* operations flags, see below */ 78 long va_spare; /* remain quad aligned */ 79 }; 80 81 /* 82 * XXX: types. But I don't want to start playing compat games in 83 * the userspace namespace too 84 */ 85 void 86 rump_vattr50_to_vattr(const struct vattr *_va50, struct vattr *va) 87 { 88 const struct vattr50 *va50 = (const struct vattr50 *)_va50; 89 90 va->va_type = va50->va_type; 91 va->va_mode = va50->va_mode; 92 va->va_nlink = va50->va_nlink; 93 va->va_uid = va50->va_uid; 94 va->va_gid = va50->va_gid; 95 va->va_fsid = (long)va50->va_fsid; 96 va->va_fileid = va50->va_fileid; 97 va->va_size = va50->va_size; 98 va->va_blocksize = va50->va_blocksize; 99 timespec50_to_timespec(&va50->va_atime, &va->va_atime); 100 timespec50_to_timespec(&va50->va_ctime, &va->va_ctime); 101 timespec50_to_timespec(&va50->va_mtime, &va->va_mtime); 102 timespec50_to_timespec(&va50->va_birthtime, &va->va_birthtime); 103 va->va_gen = va50->va_gen; 104 va->va_flags = va50->va_flags; 105 va->va_rdev = (int32_t)va50->va_rdev; 106 va->va_bytes = va50->va_bytes; 107 va->va_filerev = va50->va_filerev; 108 va->va_vaflags = va50->va_flags; 109 } 110 111 void 112 rump_vattr_to_vattr50(const struct vattr *va, struct vattr *_va50) 113 { 114 struct vattr50 *va50 = (struct vattr50 *)_va50; 115 116 va50->va_type = va->va_type; 117 va50->va_mode = va->va_mode; 118 va50->va_nlink = va->va_nlink; 119 va50->va_uid = va->va_uid; 120 va50->va_gid = va->va_gid; 121 va50->va_fsid = (u_long)va->va_fsid; 122 va50->va_fileid = va->va_fileid; 123 va50->va_size = va->va_size; 124 va50->va_blocksize = va->va_blocksize; 125 timespec_to_timespec50(&va->va_atime, &va50->va_atime); 126 timespec_to_timespec50(&va->va_ctime, &va50->va_ctime); 127 timespec_to_timespec50(&va->va_mtime, &va50->va_mtime); 128 timespec_to_timespec50(&va->va_birthtime, &va50->va_birthtime); 129 va50->va_gen = va->va_gen; 130 va50->va_flags = va->va_flags; 131 va50->va_rdev = (uint32_t)va->va_rdev; 132 va50->va_bytes = va->va_bytes; 133 va50->va_filerev = va->va_filerev; 134 va50->va_vaflags = va->va_flags; 135 } 136