linux_blkio.c revision 1.2.2.2 1 1.2.2.2 bouyer /* $NetBSD: linux_blkio.c,v 1.2.2.2 2001/01/18 09:23:13 bouyer Exp $ */
2 1.2.2.2 bouyer
3 1.2.2.2 bouyer /*
4 1.2.2.2 bouyer * Copyright (c) 2001 Wasabi Systems, Inc.
5 1.2.2.2 bouyer * All rights reserved.
6 1.2.2.2 bouyer *
7 1.2.2.2 bouyer * Written by Frank van der Linden for Wasabi Systems, Inc.
8 1.2.2.2 bouyer *
9 1.2.2.2 bouyer * Redistribution and use in source and binary forms, with or without
10 1.2.2.2 bouyer * modification, are permitted provided that the following conditions
11 1.2.2.2 bouyer * are met:
12 1.2.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
13 1.2.2.2 bouyer * notice, this list of conditions and the following disclaimer.
14 1.2.2.2 bouyer * 2. Redistributions in binary form must reproduce the above copyright
15 1.2.2.2 bouyer * notice, this list of conditions and the following disclaimer in the
16 1.2.2.2 bouyer * documentation and/or other materials provided with the distribution.
17 1.2.2.2 bouyer * 3. All advertising materials mentioning features or use of this software
18 1.2.2.2 bouyer * must display the following acknowledgement:
19 1.2.2.2 bouyer * This product includes software developed for the NetBSD Project by
20 1.2.2.2 bouyer * Wasabi Systems, Inc.
21 1.2.2.2 bouyer * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.2.2.2 bouyer * or promote products derived from this software without specific prior
23 1.2.2.2 bouyer * written permission.
24 1.2.2.2 bouyer *
25 1.2.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.2.2.2 bouyer * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.2.2.2 bouyer * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.2.2.2 bouyer * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.2.2.2 bouyer * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.2.2.2 bouyer * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.2.2.2 bouyer * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.2.2.2 bouyer * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.2.2.2 bouyer * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.2.2.2 bouyer * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.2.2.2 bouyer * POSSIBILITY OF SUCH DAMAGE.
36 1.2.2.2 bouyer */
37 1.2.2.2 bouyer
38 1.2.2.2 bouyer #include <sys/param.h>
39 1.2.2.2 bouyer #include <sys/systm.h>
40 1.2.2.2 bouyer #include <sys/ioctl.h>
41 1.2.2.2 bouyer #include <sys/file.h>
42 1.2.2.2 bouyer #include <sys/filedesc.h>
43 1.2.2.2 bouyer #include <sys/mount.h>
44 1.2.2.2 bouyer #include <sys/proc.h>
45 1.2.2.2 bouyer #include <sys/disklabel.h>
46 1.2.2.2 bouyer
47 1.2.2.2 bouyer #include <sys/syscallargs.h>
48 1.2.2.2 bouyer
49 1.2.2.2 bouyer #include <compat/linux/common/linux_types.h>
50 1.2.2.2 bouyer #include <compat/linux/common/linux_ioctl.h>
51 1.2.2.2 bouyer #include <compat/linux/common/linux_signal.h>
52 1.2.2.2 bouyer #include <compat/linux/common/linux_util.h>
53 1.2.2.2 bouyer #include <compat/linux/common/linux_blkio.h>
54 1.2.2.2 bouyer
55 1.2.2.2 bouyer #include <compat/linux/linux_syscallargs.h>
56 1.2.2.2 bouyer
57 1.2.2.2 bouyer int
58 1.2.2.2 bouyer linux_ioctl_blkio(struct proc *p, struct linux_sys_ioctl_args *uap,
59 1.2.2.2 bouyer register_t *retval)
60 1.2.2.2 bouyer {
61 1.2.2.2 bouyer u_long com;
62 1.2.2.2 bouyer long size;
63 1.2.2.2 bouyer int error;
64 1.2.2.2 bouyer struct filedesc *fdp;
65 1.2.2.2 bouyer struct file *fp;
66 1.2.2.2 bouyer int (*ioctlf) __P((struct file *, u_long, caddr_t, struct proc *));
67 1.2.2.2 bouyer struct partinfo partp;
68 1.2.2.2 bouyer struct disklabel label;
69 1.2.2.2 bouyer
70 1.2.2.2 bouyer fdp = p->p_fd;
71 1.2.2.2 bouyer if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles ||
72 1.2.2.2 bouyer (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL ||
73 1.2.2.2 bouyer (fp->f_iflags & FIF_WANTCLOSE) != 0)
74 1.2.2.2 bouyer return (EBADF);
75 1.2.2.2 bouyer
76 1.2.2.2 bouyer FILE_USE(fp);
77 1.2.2.2 bouyer error = 0;
78 1.2.2.2 bouyer ioctlf = fp->f_ops->fo_ioctl;
79 1.2.2.2 bouyer com = SCARG(uap, com);
80 1.2.2.2 bouyer
81 1.2.2.2 bouyer switch (com) {
82 1.2.2.2 bouyer case LINUX_BLKGETSIZE:
83 1.2.2.2 bouyer /*
84 1.2.2.2 bouyer * Try to get the partition size of this device. If that
85 1.2.2.2 bouyer * fails, it may be a disk without label; try to get
86 1.2.2.2 bouyer * the default label and compute the size from it.
87 1.2.2.2 bouyer */
88 1.2.2.2 bouyer error = ioctlf(fp, DIOCGPART, (caddr_t)&partp, p);
89 1.2.2.2 bouyer if (error != 0) {
90 1.2.2.2 bouyer error = ioctlf(fp, DIOCGDEFLABEL, (caddr_t)&label, p);
91 1.2.2.2 bouyer if (error != 0)
92 1.2.2.2 bouyer break;
93 1.2.2.2 bouyer size = label.d_nsectors * label.d_ntracks *
94 1.2.2.2 bouyer label.d_ncylinders;
95 1.2.2.2 bouyer } else
96 1.2.2.2 bouyer size = partp.part->p_size;
97 1.2.2.2 bouyer error = copyout(&size, SCARG(uap, data), sizeof size);
98 1.2.2.2 bouyer break;
99 1.2.2.2 bouyer case LINUX_BLKSECTGET:
100 1.2.2.2 bouyer error = ioctlf(fp, DIOCGDEFLABEL, (caddr_t)&label, p);
101 1.2.2.2 bouyer if (error != 0)
102 1.2.2.2 bouyer break;
103 1.2.2.2 bouyer error = copyout(&label.d_secsize, SCARG(uap, data),
104 1.2.2.2 bouyer sizeof label.d_secsize);
105 1.2.2.2 bouyer break;
106 1.2.2.2 bouyer case LINUX_BLKROSET:
107 1.2.2.2 bouyer case LINUX_BLKROGET:
108 1.2.2.2 bouyer case LINUX_BLKRRPART:
109 1.2.2.2 bouyer case LINUX_BLKFLSBUF:
110 1.2.2.2 bouyer case LINUX_BLKRASET:
111 1.2.2.2 bouyer case LINUX_BLKRAGET:
112 1.2.2.2 bouyer case LINUX_BLKFRASET:
113 1.2.2.2 bouyer case LINUX_BLKFRAGET:
114 1.2.2.2 bouyer case LINUX_BLKSECTSET:
115 1.2.2.2 bouyer case LINUX_BLKSSZGET:
116 1.2.2.2 bouyer case LINUX_BLKPG:
117 1.2.2.2 bouyer default:
118 1.2.2.2 bouyer error = ENOTTY;
119 1.2.2.2 bouyer }
120 1.2.2.2 bouyer
121 1.2.2.2 bouyer FILE_UNUSE(fp, p);
122 1.2.2.2 bouyer
123 1.2.2.2 bouyer return error;
124 1.2.2.2 bouyer }
125