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