linux_file64.c revision 1.1 1 1.1 jdolecek /* $NetBSD: linux_file64.c,v 1.1 2000/12/12 19:02:00 jdolecek Exp $ */
2 1.1 jdolecek
3 1.1 jdolecek /*-
4 1.1 jdolecek * Copyright (c) 1995, 1998, 2000 The NetBSD Foundation, Inc.
5 1.1 jdolecek * All rights reserved.
6 1.1 jdolecek *
7 1.1 jdolecek * This code is derived from software contributed to The NetBSD Foundation
8 1.1 jdolecek * by Frank van der Linden and Eric Haszlakiewicz.
9 1.1 jdolecek *
10 1.1 jdolecek * Redistribution and use in source and binary forms, with or without
11 1.1 jdolecek * modification, are permitted provided that the following conditions
12 1.1 jdolecek * are met:
13 1.1 jdolecek * 1. Redistributions of source code must retain the above copyright
14 1.1 jdolecek * notice, this list of conditions and the following disclaimer.
15 1.1 jdolecek * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 jdolecek * notice, this list of conditions and the following disclaimer in the
17 1.1 jdolecek * documentation and/or other materials provided with the distribution.
18 1.1 jdolecek * 3. All advertising materials mentioning features or use of this software
19 1.1 jdolecek * must display the following acknowledgement:
20 1.1 jdolecek * This product includes software developed by the NetBSD
21 1.1 jdolecek * Foundation, Inc. and its contributors.
22 1.1 jdolecek * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 jdolecek * contributors may be used to endorse or promote products derived
24 1.1 jdolecek * from this software without specific prior written permission.
25 1.1 jdolecek *
26 1.1 jdolecek * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 jdolecek * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 jdolecek * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 jdolecek * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 jdolecek * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 jdolecek * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 jdolecek * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 jdolecek * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 jdolecek * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 jdolecek * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 jdolecek * POSSIBILITY OF SUCH DAMAGE.
37 1.1 jdolecek */
38 1.1 jdolecek
39 1.1 jdolecek /*
40 1.1 jdolecek * Linux 64bit filesystem calls. Used on 32bit archs, not used on 64bit ones.
41 1.1 jdolecek */
42 1.1 jdolecek
43 1.1 jdolecek #include <sys/param.h>
44 1.1 jdolecek #include <sys/systm.h>
45 1.1 jdolecek #include <sys/namei.h>
46 1.1 jdolecek #include <sys/proc.h>
47 1.1 jdolecek #include <sys/file.h>
48 1.1 jdolecek #include <sys/stat.h>
49 1.1 jdolecek #include <sys/filedesc.h>
50 1.1 jdolecek #include <sys/ioctl.h>
51 1.1 jdolecek #include <sys/kernel.h>
52 1.1 jdolecek #include <sys/mount.h>
53 1.1 jdolecek #include <sys/malloc.h>
54 1.1 jdolecek #include <sys/vnode.h>
55 1.1 jdolecek #include <sys/tty.h>
56 1.1 jdolecek #include <sys/conf.h>
57 1.1 jdolecek
58 1.1 jdolecek #include <sys/syscallargs.h>
59 1.1 jdolecek
60 1.1 jdolecek #include <compat/linux/common/linux_types.h>
61 1.1 jdolecek #include <compat/linux/common/linux_signal.h>
62 1.1 jdolecek #include <compat/linux/common/linux_fcntl.h>
63 1.1 jdolecek #include <compat/linux/common/linux_util.h>
64 1.1 jdolecek #include <compat/linux/common/linux_machdep.h>
65 1.1 jdolecek
66 1.1 jdolecek #include <compat/linux/linux_syscallargs.h>
67 1.1 jdolecek
68 1.1 jdolecek static void bsd_to_linux_stat __P((struct stat *, struct linux_stat64 *));
69 1.1 jdolecek static int linux_do_stat64 __P((struct proc *, void *, register_t *, int));
70 1.1 jdolecek
71 1.1 jdolecek /*
72 1.1 jdolecek * Convert a NetBSD stat structure to a Linux stat structure.
73 1.1 jdolecek * Only the order of the fields and the padding in the structure
74 1.1 jdolecek * is different. linux_fakedev is a machine-dependent function
75 1.1 jdolecek * which optionally converts device driver major/minor numbers
76 1.1 jdolecek * (XXX horrible, but what can you do against code that compares
77 1.1 jdolecek * things against constant major device numbers? sigh)
78 1.1 jdolecek */
79 1.1 jdolecek static void
80 1.1 jdolecek bsd_to_linux_stat(bsp, lsp)
81 1.1 jdolecek struct stat *bsp;
82 1.1 jdolecek struct linux_stat64 *lsp;
83 1.1 jdolecek {
84 1.1 jdolecek lsp->lst_dev = bsp->st_dev;
85 1.1 jdolecek lsp->lst_ino = bsp->st_ino;
86 1.1 jdolecek lsp->lst_mode = (linux_mode_t)bsp->st_mode;
87 1.1 jdolecek if (bsp->st_nlink >= (1 << 15))
88 1.1 jdolecek lsp->lst_nlink = (1 << 15) - 1;
89 1.1 jdolecek else
90 1.1 jdolecek lsp->lst_nlink = (linux_nlink_t)bsp->st_nlink;
91 1.1 jdolecek lsp->lst_uid = bsp->st_uid;
92 1.1 jdolecek lsp->lst_gid = bsp->st_gid;
93 1.1 jdolecek lsp->lst_rdev = linux_fakedev(bsp->st_rdev);
94 1.1 jdolecek lsp->lst_size = bsp->st_size;
95 1.1 jdolecek lsp->lst_blksize = bsp->st_blksize;
96 1.1 jdolecek lsp->lst_blocks = bsp->st_blocks;
97 1.1 jdolecek lsp->lst_atime = bsp->st_atime;
98 1.1 jdolecek lsp->lst_mtime = bsp->st_mtime;
99 1.1 jdolecek lsp->lst_ctime = bsp->st_ctime;
100 1.1 jdolecek }
101 1.1 jdolecek
102 1.1 jdolecek /*
103 1.1 jdolecek * The stat functions below are plain sailing. stat and lstat are handled
104 1.1 jdolecek * by one function to avoid code duplication.
105 1.1 jdolecek */
106 1.1 jdolecek int
107 1.1 jdolecek linux_sys_fstat64(p, v, retval)
108 1.1 jdolecek struct proc *p;
109 1.1 jdolecek void *v;
110 1.1 jdolecek register_t *retval;
111 1.1 jdolecek {
112 1.1 jdolecek struct linux_sys_fstat64_args /* {
113 1.1 jdolecek syscallarg(int) fd;
114 1.1 jdolecek syscallarg(linux_stat64 *) sp;
115 1.1 jdolecek } */ *uap = v;
116 1.1 jdolecek struct sys___fstat13_args fsa;
117 1.1 jdolecek struct linux_stat64 tmplst;
118 1.1 jdolecek struct stat *st,tmpst;
119 1.1 jdolecek caddr_t sg;
120 1.1 jdolecek int error;
121 1.1 jdolecek
122 1.1 jdolecek sg = stackgap_init(p->p_emul);
123 1.1 jdolecek
124 1.1 jdolecek st = stackgap_alloc(&sg, sizeof (struct stat));
125 1.1 jdolecek
126 1.1 jdolecek SCARG(&fsa, fd) = SCARG(uap, fd);
127 1.1 jdolecek SCARG(&fsa, sb) = st;
128 1.1 jdolecek
129 1.1 jdolecek if ((error = sys___fstat13(p, &fsa, retval)))
130 1.1 jdolecek return error;
131 1.1 jdolecek
132 1.1 jdolecek if ((error = copyin(st, &tmpst, sizeof tmpst)))
133 1.1 jdolecek return error;
134 1.1 jdolecek
135 1.1 jdolecek bsd_to_linux_stat(&tmpst, &tmplst);
136 1.1 jdolecek
137 1.1 jdolecek if ((error = copyout(&tmplst, SCARG(uap, sp), sizeof tmplst)))
138 1.1 jdolecek return error;
139 1.1 jdolecek
140 1.1 jdolecek return 0;
141 1.1 jdolecek }
142 1.1 jdolecek
143 1.1 jdolecek static int
144 1.1 jdolecek linux_do_stat64(p, v, retval, dolstat)
145 1.1 jdolecek struct proc *p;
146 1.1 jdolecek void *v;
147 1.1 jdolecek register_t *retval;
148 1.1 jdolecek int dolstat;
149 1.1 jdolecek {
150 1.1 jdolecek struct sys___stat13_args sa;
151 1.1 jdolecek struct linux_stat64 tmplst;
152 1.1 jdolecek struct stat *st, tmpst;
153 1.1 jdolecek caddr_t sg;
154 1.1 jdolecek int error;
155 1.1 jdolecek struct linux_sys_stat64_args *uap = v;
156 1.1 jdolecek
157 1.1 jdolecek sg = stackgap_init(p->p_emul);
158 1.1 jdolecek st = stackgap_alloc(&sg, sizeof (struct stat));
159 1.1 jdolecek CHECK_ALT_EXIST(p, &sg, SCARG(uap, path));
160 1.1 jdolecek
161 1.1 jdolecek SCARG(&sa, ub) = st;
162 1.1 jdolecek SCARG(&sa, path) = SCARG(uap, path);
163 1.1 jdolecek
164 1.1 jdolecek if ((error = (dolstat ? sys___lstat13(p, &sa, retval) :
165 1.1 jdolecek sys___stat13(p, &sa, retval))))
166 1.1 jdolecek return error;
167 1.1 jdolecek
168 1.1 jdolecek if ((error = copyin(st, &tmpst, sizeof tmpst)))
169 1.1 jdolecek return error;
170 1.1 jdolecek
171 1.1 jdolecek bsd_to_linux_stat(&tmpst, &tmplst);
172 1.1 jdolecek
173 1.1 jdolecek if ((error = copyout(&tmplst, SCARG(uap, sp), sizeof tmplst)))
174 1.1 jdolecek return error;
175 1.1 jdolecek
176 1.1 jdolecek return 0;
177 1.1 jdolecek }
178 1.1 jdolecek
179 1.1 jdolecek int
180 1.1 jdolecek linux_sys_stat64(p, v, retval)
181 1.1 jdolecek struct proc *p;
182 1.1 jdolecek void *v;
183 1.1 jdolecek register_t *retval;
184 1.1 jdolecek {
185 1.1 jdolecek struct linux_sys_stat64_args /* {
186 1.1 jdolecek syscallarg(const char *) path;
187 1.1 jdolecek syscallarg(struct linux_stat64 *) sp;
188 1.1 jdolecek } */ *uap = v;
189 1.1 jdolecek
190 1.1 jdolecek return linux_do_stat64(p, uap, retval, 0);
191 1.1 jdolecek }
192 1.1 jdolecek
193 1.1 jdolecek int
194 1.1 jdolecek linux_sys_lstat64(p, v, retval)
195 1.1 jdolecek struct proc *p;
196 1.1 jdolecek void *v;
197 1.1 jdolecek register_t *retval;
198 1.1 jdolecek {
199 1.1 jdolecek struct linux_sys_lstat64_args /* {
200 1.1 jdolecek syscallarg(const char *) path;
201 1.1 jdolecek syscallarg(struct linux_stat64 *) sp;
202 1.1 jdolecek } */ *uap = v;
203 1.1 jdolecek
204 1.1 jdolecek return linux_do_stat64(p, uap, retval, 1);
205 1.1 jdolecek }
206