vfs_syscalls_12.c revision 1.27 1 1.27 christos /* $NetBSD: vfs_syscalls_12.c,v 1.27 2009/01/11 02:45:47 christos Exp $ */
2 1.1 fvdl
3 1.1 fvdl /*
4 1.1 fvdl * Copyright (c) 1989, 1993
5 1.1 fvdl * The Regents of the University of California. All rights reserved.
6 1.1 fvdl * (c) UNIX System Laboratories, Inc.
7 1.1 fvdl * All or some portions of this file are derived from material licensed
8 1.1 fvdl * to the University of California by American Telephone and Telegraph
9 1.1 fvdl * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 1.1 fvdl * the permission of UNIX System Laboratories, Inc.
11 1.1 fvdl *
12 1.1 fvdl * Redistribution and use in source and binary forms, with or without
13 1.1 fvdl * modification, are permitted provided that the following conditions
14 1.1 fvdl * are met:
15 1.1 fvdl * 1. Redistributions of source code must retain the above copyright
16 1.1 fvdl * notice, this list of conditions and the following disclaimer.
17 1.1 fvdl * 2. Redistributions in binary form must reproduce the above copyright
18 1.1 fvdl * notice, this list of conditions and the following disclaimer in the
19 1.1 fvdl * documentation and/or other materials provided with the distribution.
20 1.14 agc * 3. Neither the name of the University nor the names of its contributors
21 1.1 fvdl * may be used to endorse or promote products derived from this software
22 1.1 fvdl * without specific prior written permission.
23 1.1 fvdl *
24 1.1 fvdl * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.1 fvdl * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.1 fvdl * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.1 fvdl * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.1 fvdl * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.1 fvdl * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.1 fvdl * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.1 fvdl * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.1 fvdl * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.1 fvdl * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.1 fvdl * SUCH DAMAGE.
35 1.1 fvdl *
36 1.1 fvdl * From: @(#)vfs_syscalls.c 8.28 (Berkeley) 12/10/94
37 1.1 fvdl */
38 1.10 lukem
39 1.10 lukem #include <sys/cdefs.h>
40 1.27 christos __KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_12.c,v 1.27 2009/01/11 02:45:47 christos Exp $");
41 1.1 fvdl
42 1.1 fvdl #include <sys/param.h>
43 1.1 fvdl #include <sys/systm.h>
44 1.1 fvdl #include <sys/namei.h>
45 1.1 fvdl #include <sys/filedesc.h>
46 1.1 fvdl #include <sys/kernel.h>
47 1.1 fvdl #include <sys/file.h>
48 1.1 fvdl #include <sys/stat.h>
49 1.2 christos #include <sys/socketvar.h>
50 1.1 fvdl #include <sys/vnode.h>
51 1.1 fvdl #include <sys/mount.h>
52 1.1 fvdl #include <sys/proc.h>
53 1.1 fvdl #include <sys/uio.h>
54 1.1 fvdl #include <sys/dirent.h>
55 1.21 dsl #include <sys/vfs_syscalls.h>
56 1.1 fvdl
57 1.1 fvdl #include <sys/syscallargs.h>
58 1.1 fvdl
59 1.16 christos #include <compat/sys/stat.h>
60 1.2 christos
61 1.2 christos /*
62 1.4 wrstuden * Convert from a new to an old stat structure.
63 1.2 christos */
64 1.22 dsl void
65 1.22 dsl compat_12_stat_conv(const struct stat *st, struct stat12 *ost)
66 1.2 christos {
67 1.2 christos
68 1.2 christos ost->st_dev = st->st_dev;
69 1.2 christos ost->st_ino = st->st_ino;
70 1.4 wrstuden ost->st_mode = st->st_mode & 0xffff;
71 1.2 christos if (st->st_nlink >= (1 << 15))
72 1.2 christos ost->st_nlink = (1 << 15) - 1;
73 1.2 christos else
74 1.2 christos ost->st_nlink = st->st_nlink;
75 1.2 christos ost->st_uid = st->st_uid;
76 1.2 christos ost->st_gid = st->st_gid;
77 1.2 christos ost->st_rdev = st->st_rdev;
78 1.27 christos timespec_to_timespec50(&st->st_atimespec, &ost->st_atimespec);
79 1.27 christos timespec_to_timespec50(&st->st_mtimespec, &ost->st_mtimespec);
80 1.27 christos timespec_to_timespec50(&st->st_ctimespec, &ost->st_ctimespec);
81 1.2 christos ost->st_size = st->st_size;
82 1.3 mycroft ost->st_blocks = st->st_blocks;
83 1.2 christos ost->st_blksize = st->st_blksize;
84 1.2 christos ost->st_flags = st->st_flags;
85 1.2 christos ost->st_gen = st->st_gen;
86 1.2 christos }
87 1.3 mycroft
88 1.1 fvdl /*
89 1.1 fvdl * Read a block of directory entries in a file system independent format.
90 1.1 fvdl */
91 1.1 fvdl int
92 1.24 dsl compat_12_sys_getdirentries(struct lwp *l, const struct compat_12_sys_getdirentries_args *uap, register_t *retval)
93 1.1 fvdl {
94 1.24 dsl /* {
95 1.1 fvdl syscallarg(int) fd;
96 1.1 fvdl syscallarg(char *) buf;
97 1.1 fvdl syscallarg(u_int) count;
98 1.1 fvdl syscallarg(long *) basep;
99 1.24 dsl } */
100 1.1 fvdl struct file *fp;
101 1.1 fvdl int error, done;
102 1.1 fvdl long loff;
103 1.1 fvdl
104 1.26 ad /* fd_getvnode() will use the descriptor for us */
105 1.26 ad if ((error = fd_getvnode(SCARG(uap, fd), &fp)) != 0)
106 1.1 fvdl return error;
107 1.5 thorpej if ((fp->f_flag & FREAD) == 0) {
108 1.5 thorpej error = EBADF;
109 1.5 thorpej goto out;
110 1.5 thorpej }
111 1.1 fvdl
112 1.1 fvdl loff = fp->f_offset;
113 1.1 fvdl
114 1.1 fvdl error = vn_readdir(fp, SCARG(uap, buf), UIO_USERSPACE,
115 1.17 christos SCARG(uap, count), &done, l, 0, 0);
116 1.1 fvdl
117 1.1 fvdl error = copyout(&loff, SCARG(uap, basep), sizeof(long));
118 1.1 fvdl *retval = done;
119 1.5 thorpej out:
120 1.25 ad fd_putfile(SCARG(uap, fd));
121 1.1 fvdl return error;
122 1.2 christos }
123 1.2 christos
124 1.2 christos /*
125 1.2 christos * Get file status; this version follows links.
126 1.2 christos */
127 1.2 christos /* ARGSUSED */
128 1.2 christos int
129 1.24 dsl compat_12_sys_stat(struct lwp *l, const struct compat_12_sys_stat_args *uap, register_t *retval)
130 1.2 christos {
131 1.24 dsl /* {
132 1.3 mycroft syscallarg(const char *) path;
133 1.2 christos syscallarg(struct stat12 *) ub;
134 1.24 dsl } */
135 1.2 christos struct stat sb;
136 1.2 christos struct stat12 osb;
137 1.2 christos int error;
138 1.2 christos
139 1.25 ad error = do_sys_stat(SCARG(uap, path), FOLLOW, &sb);
140 1.2 christos if (error)
141 1.2 christos return (error);
142 1.22 dsl compat_12_stat_conv(&sb, &osb);
143 1.3 mycroft error = copyout(&osb, SCARG(uap, ub), sizeof (osb));
144 1.2 christos return (error);
145 1.2 christos }
146 1.2 christos
147 1.2 christos
148 1.2 christos /*
149 1.2 christos * Get file status; this version does not follow links.
150 1.2 christos */
151 1.2 christos /* ARGSUSED */
152 1.2 christos int
153 1.24 dsl compat_12_sys_lstat(struct lwp *l, const struct compat_12_sys_lstat_args *uap, register_t *retval)
154 1.2 christos {
155 1.24 dsl /* {
156 1.3 mycroft syscallarg(const char *) path;
157 1.2 christos syscallarg(struct stat12 *) ub;
158 1.24 dsl } */
159 1.2 christos struct stat sb;
160 1.2 christos struct stat12 osb;
161 1.2 christos int error;
162 1.2 christos
163 1.25 ad error = do_sys_stat(SCARG(uap, path), NOFOLLOW, &sb);
164 1.2 christos if (error)
165 1.2 christos return (error);
166 1.22 dsl compat_12_stat_conv(&sb, &osb);
167 1.2 christos error = copyout(&osb, SCARG(uap, ub), sizeof (osb));
168 1.2 christos return (error);
169 1.2 christos }
170 1.2 christos
171 1.2 christos /*
172 1.2 christos * Return status information about a file descriptor.
173 1.2 christos */
174 1.2 christos /* ARGSUSED */
175 1.2 christos int
176 1.24 dsl compat_12_sys_fstat(struct lwp *l, const struct compat_12_sys_fstat_args *uap, register_t *retval)
177 1.2 christos {
178 1.24 dsl /* {
179 1.2 christos syscallarg(int) fd;
180 1.2 christos syscallarg(struct stat12 *) sb;
181 1.24 dsl } */
182 1.2 christos int fd = SCARG(uap, fd);
183 1.6 augustss struct file *fp;
184 1.2 christos struct stat ub;
185 1.2 christos struct stat12 oub;
186 1.2 christos int error;
187 1.2 christos
188 1.25 ad if ((fp = fd_getfile(fd)) == NULL)
189 1.2 christos return (EBADF);
190 1.25 ad error = (*fp->f_ops->fo_stat)(fp, &ub);
191 1.25 ad fd_putfile(fd);
192 1.3 mycroft if (error == 0) {
193 1.22 dsl compat_12_stat_conv(&ub, &oub);
194 1.3 mycroft error = copyout(&oub, SCARG(uap, sb), sizeof (oub));
195 1.3 mycroft }
196 1.2 christos return (error);
197 1.1 fvdl }
198