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