summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorsten Lockert <tholo@cvs.openbsd.org>2001-04-09 06:53:46 +0000
committerThorsten Lockert <tholo@cvs.openbsd.org>2001-04-09 06:53:46 +0000
commit505a042a913b0e4324612c89276096104be13025 (patch)
treec3faf32a8a7cb93d803bbebe0ad0b7af4973d89b
parent86de17e962b949dcb8379810350e529762128b3b (diff)
Handle more Linux ioctls; from NetBSD. ok deraadt@
-rw-r--r--sys/compat/linux/files.linux5
-rw-r--r--sys/compat/linux/linux_blkio.c133
-rw-r--r--sys/compat/linux/linux_blkio.h61
-rw-r--r--sys/compat/linux/linux_fdio.c162
-rw-r--r--sys/compat/linux/linux_fdio.h201
-rw-r--r--sys/compat/linux/linux_hdio.c193
-rw-r--r--sys/compat/linux/linux_hdio.h89
-rw-r--r--sys/compat/linux/linux_ioctl.c12
-rw-r--r--sys/compat/linux/linux_ioctl.h55
9 files changed, 905 insertions, 6 deletions
diff --git a/sys/compat/linux/files.linux b/sys/compat/linux/files.linux
index 407c37545fe..83326f1684c 100644
--- a/sys/compat/linux/files.linux
+++ b/sys/compat/linux/files.linux
@@ -1,4 +1,4 @@
-# $OpenBSD: files.linux,v 1.12 2001/04/02 21:43:11 niklas Exp $
+# $OpenBSD: files.linux,v 1.13 2001/04/09 06:53:44 tholo Exp $
# $NetBSD: files.linux,v 1.4 1996/03/08 04:55:59 mycroft Exp $
#
# Config.new file description for machine-independent Linux compat code.
@@ -7,12 +7,15 @@
# ports should define any machine-specific files they need in their
# own file lists.
+file compat/linux/linux_blkio.c compat_linux
file compat/linux/linux_cdrom.c compat_linux
file compat/linux/linux_error.c compat_linux
file compat/linux/linux_exec.c compat_linux
+file compat/linux/linux_fdio.c compat_linux
file compat/linux/linux_file.c compat_linux
file compat/linux/linux_file64.c compat_linux
file compat/linux/linux_getcwd.c compat_linux
+file compat/linux/linux_hdio.c compat_linux
file compat/linux/linux_ioctl.c compat_linux
file compat/linux/linux_ipc.c compat_linux
file compat/linux/linux_misc.c compat_linux
diff --git a/sys/compat/linux/linux_blkio.c b/sys/compat/linux/linux_blkio.c
new file mode 100644
index 00000000000..41e9e7c8817
--- /dev/null
+++ b/sys/compat/linux/linux_blkio.c
@@ -0,0 +1,133 @@
+/* $OpenBSD: linux_blkio.c,v 1.1 2001/04/09 06:53:44 tholo Exp $ */
+/* $NetBSD: linux_blkio.c,v 1.3 2001/01/18 17:48:04 tv Exp $ */
+
+/*
+ * Copyright (c) 2001 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Frank van der Linden for Wasabi Systems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed for the NetBSD Project by
+ * Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/ioctl.h>
+#include <sys/file.h>
+#include <sys/filedesc.h>
+#include <sys/mount.h>
+#include <sys/proc.h>
+#include <sys/disklabel.h>
+
+#include <sys/syscallargs.h>
+
+#include <compat/linux/linux_types.h>
+#include <compat/linux/linux_ioctl.h>
+#include <compat/linux/linux_signal.h>
+#include <compat/linux/linux_util.h>
+#include <compat/linux/linux_blkio.h>
+
+#include <compat/linux/linux_syscallargs.h>
+
+int
+linux_ioctl_blkio(struct proc *p, struct linux_sys_ioctl_args *uap,
+ register_t *retval)
+{
+ u_long com;
+ long size;
+ int error;
+ struct filedesc *fdp;
+ struct file *fp;
+ int (*ioctlf) __P((struct file *, u_long, caddr_t, struct proc *));
+ struct partinfo partp;
+ struct disklabel label;
+
+ fdp = p->p_fd;
+#if 1
+ if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles ||
+ (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL)
+ return (EBADF);
+#else
+ if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles ||
+ (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL ||
+ (fp->f_iflags & FIF_WANTCLOSE) != 0)
+ return (EBADF);
+
+ FILE_USE(fp);
+#endif
+ error = 0;
+ ioctlf = fp->f_ops->fo_ioctl;
+ com = SCARG(uap, com);
+
+ switch (com) {
+ case LINUX_BLKGETSIZE:
+ /*
+ * Try to get the partition size of this device. If that
+ * fails, it may be a disk without label; try to get
+ * the default label and compute the size from it.
+ */
+ error = ioctlf(fp, DIOCGPART, (caddr_t)&partp, p);
+ if (error != 0) {
+ error = ioctlf(fp, DIOCGDINFO, (caddr_t)&label, p);
+ if (error != 0)
+ break;
+ size = label.d_nsectors * label.d_ntracks *
+ label.d_ncylinders;
+ } else
+ size = partp.part->p_size;
+ error = copyout(&size, SCARG(uap, data), sizeof size);
+ break;
+ case LINUX_BLKSECTGET:
+ error = ioctlf(fp, DIOCGDINFO, (caddr_t)&label, p);
+ if (error != 0)
+ break;
+ error = copyout(&label.d_secsize, SCARG(uap, data),
+ sizeof label.d_secsize);
+ break;
+ case LINUX_BLKROSET:
+ case LINUX_BLKROGET:
+ case LINUX_BLKRRPART:
+ case LINUX_BLKFLSBUF:
+ case LINUX_BLKRASET:
+ case LINUX_BLKRAGET:
+ case LINUX_BLKFRASET:
+ case LINUX_BLKFRAGET:
+ case LINUX_BLKSECTSET:
+ case LINUX_BLKSSZGET:
+ case LINUX_BLKPG:
+ default:
+ error = ENOTTY;
+ }
+
+#ifdef notyet
+ FILE_UNUSE(fp, p);
+#endif
+
+ return error;
+}
diff --git a/sys/compat/linux/linux_blkio.h b/sys/compat/linux/linux_blkio.h
new file mode 100644
index 00000000000..944946827e2
--- /dev/null
+++ b/sys/compat/linux/linux_blkio.h
@@ -0,0 +1,61 @@
+/* $OpenBSD: linux_blkio.h,v 1.1 2001/04/09 06:53:44 tholo Exp $ */
+/* $NetBSD: linux_blkio.h,v 1.2 2001/01/18 17:48:04 tv Exp $ */
+
+/*
+ * Copyright (c) 2001 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Frank van der Linden for Wasabi Systems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed for the NetBSD Project by
+ * Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Definitions for ioctl calls that work on filesystems, as defined
+ * in <linux/fs.h>
+ */
+
+#ifndef _LINUX_BLKIO_H
+#define _LINUX_BLKIO_H
+
+#define LINUX_BLKROSET _LINUX_IO(0x12, 93)
+#define LINUX_BLKROGET _LINUX_IO(0x12, 94)
+#define LINUX_BLKRRPART _LINUX_IO(0x12, 95)
+#define LINUX_BLKGETSIZE _LINUX_IO(0x12, 96)
+#define LINUX_BLKFLSBUF _LINUX_IO(0x12, 97)
+#define LINUX_BLKRASET _LINUX_IO(0x12, 98)
+#define LINUX_BLKRAGET _LINUX_IO(0x12, 99)
+#define LINUX_BLKFRASET _LINUX_IO(0x12, 100)
+#define LINUX_BLKFRAGET _LINUX_IO(0x12, 101)
+#define LINUX_BLKSECTSET _LINUX_IO(0x12, 102)
+#define LINUX_BLKSECTGET _LINUX_IO(0x12, 103)
+#define LINUX_BLKSSZGET _LINUX_IO(0x12, 104)
+#define LINUX_BLKPG _LINUX_IO(0x12, 105)
+
+#endif /* _LINUX_BLKIO_H */
diff --git a/sys/compat/linux/linux_fdio.c b/sys/compat/linux/linux_fdio.c
new file mode 100644
index 00000000000..7c8db69da10
--- /dev/null
+++ b/sys/compat/linux/linux_fdio.c
@@ -0,0 +1,162 @@
+/* $OpenBSD: linux_fdio.c,v 1.1 2001/04/09 06:53:44 tholo Exp $ */
+/* $NetBSD: linux_fdio.c,v 1.1 2000/12/10 14:12:16 fvdl Exp $ */
+
+/*
+ * Copyright (c) 2000 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Frank van der Linden for Wasabi Systems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed for the NetBSD Project by
+ * Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/ioctl.h>
+#include <sys/file.h>
+#include <sys/filedesc.h>
+#include <sys/mount.h>
+#include <sys/proc.h>
+#include <sys/disklabel.h>
+
+#include <sys/syscallargs.h>
+
+#include <dev/isa/fdreg.h>
+
+#include <compat/linux/linux_types.h>
+#include <compat/linux/linux_ioctl.h>
+#include <compat/linux/linux_signal.h>
+#include <compat/linux/linux_util.h>
+#include <compat/linux/linux_fdio.h>
+
+#include <machine/ioctl_fd.h>
+
+#include <compat/linux/linux_syscallargs.h>
+
+int
+linux_ioctl_fdio(struct proc *p, struct linux_sys_ioctl_args *uap,
+ register_t *retval)
+{
+ struct filedesc *fdp;
+ struct file *fp;
+ int error;
+ int (*ioctlf) __P((struct file *, u_long, caddr_t, struct proc *));
+ u_long com;
+ struct fd_type fparams;
+ struct linux_floppy_struct lflop;
+ struct linux_floppy_drive_struct ldrive;
+
+ com = (u_long)SCARG(uap, data);
+
+ fdp = p->p_fd;
+#if 1
+ if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles ||
+ (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL)
+ return (EBADF);
+#else
+ if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles ||
+ (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL ||
+ (fp->f_iflags & FIF_WANTCLOSE) != 0)
+ return (EBADF);
+
+ FILE_USE(fp);
+#endif
+
+ com = SCARG(uap, com);
+ ioctlf = fp->f_ops->fo_ioctl;
+
+ retval[0] = error = 0;
+
+ switch (com) {
+ case LINUX_FDMSGON:
+ case LINUX_FDMSGOFF:
+ case LINUX_FDTWADDLE:
+ case LINUX_FDCLRPRM:
+ /* whatever you say */
+ break;
+ case LINUX_FDPOLLDRVSTAT:
+ /*
+ * Just fill in some innocent defaults.
+ */
+ memset(&ldrive, 0, sizeof ldrive);
+ ldrive.fd_ref = 1;
+ ldrive.maxblock = 2;
+ ldrive.maxtrack = ldrive.track = 1;
+ ldrive.flags = LINUX_FD_DISK_WRITABLE;
+ error = copyout(&ldrive, SCARG(uap, data), sizeof ldrive);
+ break;
+ case LINUX_FDGETPRM:
+ error = ioctlf(fp, FD_GTYPE, (caddr_t)&fparams, p);
+ if (error != 0)
+ break;
+ lflop.size = fparams.heads * fparams.sectrac * fparams.tracks;
+ lflop.sect = fparams.sectrac;
+ lflop.head = fparams.heads;
+ lflop.track = fparams.tracks;
+ lflop.stretch = fparams.step == 2 ? 1 : 0;
+ lflop.spec1 = fparams.steprate;
+ lflop.gap = fparams.gap1;
+ lflop.fmt_gap = fparams.gap2;
+ lflop.rate = fparams.rate;
+
+ error = copyout(&lflop, SCARG(uap, data), sizeof lflop);
+ break;
+ case LINUX_FDSETPRM:
+ /*
+ * Should use FDIOCSETFORMAT here, iff its interface
+ * is extended.
+ */
+ case LINUX_FDDEFPRM:
+ case LINUX_FDFMTBEG:
+ case LINUX_FDFMTTRK:
+ case LINUX_FDFMTEND:
+ case LINUX_FDSETEMSGTRESH:
+ case LINUX_FDFLUSH:
+ case LINUX_FDSETMAXERRS:
+ case LINUX_FDGETMAXERRS:
+ case LINUX_FDGETDRVTYP:
+ case LINUX_FDSETDRVPRM:
+ case LINUX_FDGETDRVPRM:
+ case LINUX_FDGETDRVSTAT:
+ case LINUX_FDRESET:
+ case LINUX_FDGETFDCSTAT:
+ case LINUX_FDWERRORCLR:
+ case LINUX_FDWERRORGET:
+ case LINUX_FDRAWCMD:
+ case LINUX_FDEJECT:
+ default:
+ error = EINVAL;
+ }
+
+#ifdef notdef
+ FILE_UNUSE(fp, p);
+#endif
+
+ return 0;
+}
diff --git a/sys/compat/linux/linux_fdio.h b/sys/compat/linux/linux_fdio.h
new file mode 100644
index 00000000000..99f60335548
--- /dev/null
+++ b/sys/compat/linux/linux_fdio.h
@@ -0,0 +1,201 @@
+/* $OpenBSD: linux_fdio.h,v 1.1 2001/04/09 06:53:44 tholo Exp $ */
+/* $NetBSD: linux_fdio.h,v 1.1 2000/12/10 14:12:16 fvdl Exp $ */
+
+/*
+ * Copyright (c) 2000 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Frank van der Linden for Wasabi Systems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed for the NetBSD Project by
+ * Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_FDIO_H
+#define _LINUX_FDIO_H
+
+/*
+ * Linux floppy ioctl call structures and defines.
+ */
+
+struct linux_floppy_struct {
+ u_int size;
+ u_int sect;
+ u_int head;
+ u_int track;
+ u_int stretch;
+ u_char gap;
+ u_char rate;
+ u_char spec1;
+ u_char fmt_gap;
+ const char *name;
+};
+
+struct linux_floppy_max_errors {
+ u_int abort;
+ u_int read_track;
+ u_int reset;
+ u_int recal;
+ u_int reporting;
+};
+
+struct linux_floppy_drive_params {
+ char cmos;
+ u_long max_dtr;
+ u_long hlt;
+ u_long hut;
+ u_long srt;
+ u_long spinup;
+ u_long spindown;
+ u_char spindown_offset;
+ u_char select_delay;
+ u_char rps;
+ u_char tracks;
+ u_long timeout;
+ u_char interleave_sect;
+ struct linux_floppy_max_errors max_errors;
+ char flags;
+ char read_track;
+ short autodetect[8];
+ int checkfreq;
+ int native_format;
+};
+
+struct linux_floppy_drive_struct {
+ u_long flags;
+ u_long spinup_date;
+ u_long select_date;
+ u_long first_read_date;
+ short probed_format;
+ short track;
+ short maxblock;
+ short maxtrack;
+ int generation;
+ int keep_data;
+ int fd_ref;
+ int fd_device;
+ u_long last_checked;
+ char *dmabuf;
+ int bufblocks;
+};
+
+#define LINUX_FD_NEED_TWADDLE 0x01
+#define LINUX_FD_VERIFY 0x02
+#define LINUX_FD_DISK_NEWCHANGE 0x04
+#define LINUX_FD_DISK_CHANGED 0x10
+#define LINUX_FD_DISK_WRITABLE 0x20
+
+
+struct linux_floppy_fdc_state {
+ int spec1;
+ int spec2;
+ int dtr;
+ u_char version;
+ u_char dor;
+ u_long address;
+ u_int rawcmd:2;
+ u_int reset:1;
+ u_int need_configure:1;
+ u_int perp_mode:2;
+ u_int has_fifo:1;
+ u_int driver_version;
+ u_char track[4];
+};
+
+struct linux_floppy_write_errors {
+ u_int write_errors;
+ u_long first_error_sector;
+ u_int first_error_generation;
+ u_long last_error_sector;
+ u_int last_error_generation;
+ u_int badness;
+};
+
+struct linux_floppy_raw_cmd {
+ u_int flags;
+ void *data;
+ caddr_t kernel_data;
+ struct floppy_raw_cmd *next;
+ long length;
+ long phys_length;
+ int buffer_length;
+ u_char rate;
+ u_char cmd_count;
+ u_char cmd[16];
+ u_char reply_count;
+ u_char reply[16];
+ int track;
+ int resultcode;
+ int reserved1;
+ int reserved2;
+};
+
+struct linux_format_descr {
+ u_int device;
+ u_int head;
+ u_int track;
+};
+
+typedef char linux_floppy_drive_name[16];
+
+#define LINUX_FDCLRPRM _LINUX_IO(2, 0x41)
+#define LINUX_FDSETPRM _LINUX_IOW(2, 0x42, struct linux_floppy_struct)
+#define LINUX_FDDEFPRM _LINUX_IOW(2, 0x43, struct linux_floppy_struct)
+#define LINUX_FDGETPRM _LINUX_IOR(2, 0x04, struct linux_floppy_struct)
+#define LINUX_FDMSGON _LINUX_IO(2, 0x45)
+#define LINUX_FDMSGOFF _LINUX_IO(2, 0x46)
+#define LINUX_FDFMTBEG _LINUX_IO(2, 0x47)
+#define LINUX_FDFMTTRK _LINUX_IOW(2, 0x48, struct linux_format_descr)
+#define LINUX_FDFMTEND _LINUX_IO(2, 0x49)
+#define LINUX_FDSETEMSGTRESH _LINUX_IO(2, 0x4a)
+#define LINUX_FDFLUSH _LINUX_IO(2, 0x4b)
+#define LINUX_FDSETMAXERRS \
+ _LINUX_IOW(2, 0x4c, struct linux_floppy_max_errors)
+#define LINUX_FDGETMAXERRS \
+ _LINUX_IOR(2, 0x0e, struct linux_floppy_max_errors)
+#define LINUX_FDGETDRVTYP _LINUX_IOR(2, 0x0f, linux_floppy_drive_name)
+/* 0x90 is not a typo, that's how it's listed in the Linux include file */
+#define LINUX_FDSETDRVPRM \
+ _LINUX_IOW(2, 0x90, struct linux_floppy_drive_params)
+#define LINUX_FDGETDRVPRM \
+ _LINUX_IOR(2, 0x11, struct linux_floppy_drive_params)
+#define LINUX_FDGETDRVSTAT \
+ _LINUX_IOR(2, 0x12, struct linux_floppy_drive_struct)
+#define LINUX_FDPOLLDRVSTAT \
+ _LINUX_IOR(2, 0x13, struct linux_floppy_drive_struct)
+#define LINUX_FDRESET _LINUX_IO(2, 0x54)
+#define LINUX_FDGETFDCSTAT \
+ _LINUX_IOR(2, 0x15, struct linux_floppy_fdc_state)
+#define LINUX_FDWERRORCLR _LINUX_IO(2, 0x56)
+#define LINUX_FDWERRORGET \
+ _LINUX_IOR(2, 0x17, struct linux_floppy_write_errors)
+#define LINUX_FDRAWCMD _LINUX_IO(2, 0x58)
+#define LINUX_FDTWADDLE _LINUX_IO(2, 0x59)
+#define LINUX_FDEJECT _LINUX_IO(2, 0x5a)
+
+#endif /* _LINUX_FDIO_H */
diff --git a/sys/compat/linux/linux_hdio.c b/sys/compat/linux/linux_hdio.c
new file mode 100644
index 00000000000..1e4c6c03d3a
--- /dev/null
+++ b/sys/compat/linux/linux_hdio.c
@@ -0,0 +1,193 @@
+/* $OpenBSD: linux_hdio.c,v 1.1 2001/04/09 06:53:45 tholo Exp $ */
+/* $NetBSD: linux_hdio.c,v 1.1 2000/12/10 14:12:17 fvdl Exp $ */
+
+/*
+ * Copyright (c) 2000 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Frank van der Linden for Wasabi Systems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed for the NetBSD Project by
+ * Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/ioctl.h>
+#include <sys/file.h>
+#include <sys/filedesc.h>
+#include <sys/mount.h>
+#include <sys/proc.h>
+#include <sys/disklabel.h>
+
+#include <dev/ata/atareg.h>
+#include <dev/ic/wdcreg.h>
+#include <sys/ataio.h>
+
+#include <sys/syscallargs.h>
+
+#include <compat/linux/linux_types.h>
+#include <compat/linux/linux_ioctl.h>
+#include <compat/linux/linux_signal.h>
+#include <compat/linux/linux_util.h>
+#include <compat/linux/linux_hdio.h>
+
+#include <compat/linux/linux_syscallargs.h>
+
+int
+linux_ioctl_hdio(struct proc *p, struct linux_sys_ioctl_args *uap,
+ register_t *retval)
+{
+ u_long com;
+ int error, error1;
+ caddr_t sg;
+ struct filedesc *fdp;
+ struct file *fp;
+ int (*ioctlf) __P((struct file *, u_long, caddr_t, struct proc *));
+ struct ataparams *atap, ata;
+ struct atareq req;
+ struct disklabel label, *labp;
+ struct partinfo partp;
+ struct linux_hd_geometry hdg;
+ struct linux_hd_big_geometry hdg_big;
+
+ fdp = p->p_fd;
+#if 1
+ if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles ||
+ (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL)
+ return (EBADF);
+#else
+ if ((u_int)SCARG(uap, fd) >= fdp->fd_nfiles ||
+ (fp = fdp->fd_ofiles[SCARG(uap, fd)]) == NULL ||
+ (fp->f_iflags & FIF_WANTCLOSE) != 0)
+ return (EBADF);
+
+ FILE_USE(fp);
+#endif
+
+ com = SCARG(uap, com);
+ ioctlf = fp->f_ops->fo_ioctl;
+ retval[0] = error = 0;
+
+ com = SCARG(uap, com);
+
+ switch (com) {
+ case LINUX_HDIO_OBSOLETE_IDENTITY:
+ case LINUX_HDIO_GET_IDENTITY:
+ sg = stackgap_init(p->p_emul);
+ atap = stackgap_alloc(&sg, DEV_BSIZE);
+ if (atap == NULL) {
+ error = ENOMEM;
+ break;
+ }
+
+ req.flags = ATACMD_READ;
+ req.command = WDCC_IDENTIFY;
+ req.databuf = (caddr_t)atap;
+ req.datalen = DEV_BSIZE;
+ req.timeout = 1000;
+ error = ioctlf(fp, ATAIOCCOMMAND, (caddr_t)&req, p);
+ if (error != 0)
+ break;
+ if (req.retsts != ATACMD_OK)
+ return EIO;
+ error = copyin(atap, &ata, sizeof ata);
+ if (error != 0)
+ break;
+ /*
+ * 142 is the size of the old structure used by Linux,
+ * which doesn't seem to be defined anywhere anymore.
+ */
+ error = copyout(&ata, SCARG(uap, data),
+ com == LINUX_HDIO_GET_IDENTITY ? sizeof ata : 142);
+ break;
+ case LINUX_HDIO_GETGEO:
+ error = linux_machdepioctl(p, uap, retval);
+ if (error == 0)
+ break;
+ error = ioctlf(fp, DIOCGDINFO, (caddr_t)&label, p);
+ error1 = ioctlf(fp, DIOCGPART, (caddr_t)&partp, p);
+ if (error != 0 && error1 != 0) {
+ error = error1;
+ break;
+ }
+ labp = error != 0 ? &label : partp.disklab;
+ hdg.start = error1 != 0 ? partp.part->p_offset : 0;
+ hdg.heads = labp->d_ntracks;
+ hdg.cylinders = labp->d_ncylinders;
+ hdg.sectors = labp->d_nsectors;
+ error = copyout(&hdg, SCARG(uap, data), sizeof hdg);
+ break;
+ case LINUX_HDIO_GETGEO_BIG:
+ error = linux_machdepioctl(p, uap, retval);
+ if (error == 0)
+ break;
+ case LINUX_HDIO_GETGEO_BIG_RAW:
+ error = ioctlf(fp, DIOCGDINFO, (caddr_t)&label, p);
+ error1 = ioctlf(fp, DIOCGPART, (caddr_t)&partp, p);
+ if (error != 0 && error1 != 0) {
+ error = error1;
+ break;
+ }
+ labp = error != 0 ? &label : partp.disklab;
+ hdg_big.start = error1 != 0 ? partp.part->p_offset : 0;
+ hdg_big.heads = labp->d_ntracks;
+ hdg_big.cylinders = labp->d_ncylinders;
+ hdg_big.sectors = labp->d_nsectors;
+ error = copyout(&hdg_big, SCARG(uap, data), sizeof hdg_big);
+ break;
+ case LINUX_HDIO_GET_UNMASKINTR:
+ case LINUX_HDIO_GET_MULTCOUNT:
+ case LINUX_HDIO_GET_KEEPSETTINGS:
+ case LINUX_HDIO_GET_32BIT:
+ case LINUX_HDIO_GET_NOWERR:
+ case LINUX_HDIO_GET_DMA:
+ case LINUX_HDIO_GET_NICE:
+ case LINUX_HDIO_DRIVE_RESET:
+ case LINUX_HDIO_TRISTATE_HWIF:
+ case LINUX_HDIO_DRIVE_TASK:
+ case LINUX_HDIO_DRIVE_CMD:
+ case LINUX_HDIO_SET_MULTCOUNT:
+ case LINUX_HDIO_SET_UNMASKINTR:
+ case LINUX_HDIO_SET_KEEPSETTINGS:
+ case LINUX_HDIO_SET_32BIT:
+ case LINUX_HDIO_SET_NOWERR:
+ case LINUX_HDIO_SET_DMA:
+ case LINUX_HDIO_SET_PIO_MODE:
+ case LINUX_HDIO_SCAN_HWIF:
+ case LINUX_HDIO_SET_NICE:
+ case LINUX_HDIO_UNREGISTER_HWIF:
+ error = EINVAL;
+ }
+
+#ifdef notyet
+ FILE_UNUSE(fp, p);
+#endif
+
+ return error;
+}
diff --git a/sys/compat/linux/linux_hdio.h b/sys/compat/linux/linux_hdio.h
new file mode 100644
index 00000000000..fc76ad416ac
--- /dev/null
+++ b/sys/compat/linux/linux_hdio.h
@@ -0,0 +1,89 @@
+/* $OpenBSD: linux_hdio.h,v 1.1 2001/04/09 06:53:45 tholo Exp $ */
+/* $NetBSD: linux_hdio.h,v 1.1 2000/12/10 14:12:17 fvdl Exp $ */
+
+/*
+ * Copyright (c) 2000 Wasabi Systems, Inc.
+ * All rights reserved.
+ *
+ * Written by Frank van der Linden for Wasabi Systems, Inc.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed for the NetBSD Project by
+ * Wasabi Systems, Inc.
+ * 4. The name of Wasabi Systems, Inc. may not be used to endorse
+ * or promote products derived from this software without specific prior
+ * written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_HDIO_H
+#define _LINUX_HDIO_H
+
+/*
+ * Linux 'hd' (mostly really IDE disk) ioctl calls.
+ */
+
+#define LINUX_HDIO_GETGEO 0x0301
+#define LINUX_HDIO_GETGEO_BIG 0x0330
+#define LINUX_HDIO_GETGEO_BIG_RAW 0x0331
+#define LINUX_HDIO_GET_UNMASKINTR 0x0302
+#define LINUX_HDIO_GET_MULTCOUNT 0x0304
+#define LINUX_HDIO_OBSOLETE_IDENTITY 0x0307
+#define LINUX_HDIO_GET_KEEPSETTINGS 0x0308
+#define LINUX_HDIO_GET_32BIT 0x0309
+#define LINUX_HDIO_GET_NOWERR 0x030a
+#define LINUX_HDIO_GET_DMA 0x030b
+#define LINUX_HDIO_GET_NICE 0x030c
+#define LINUX_HDIO_GET_IDENTITY 0x030d
+
+#define LINUX_HDIO_DRIVE_RESET 0x031c
+#define LINUX_HDIO_TRISTATE_HWIF 0x031d
+#define LINUX_HDIO_DRIVE_TASK 0x031e
+#define LINUX_HDIO_DRIVE_CMD 0x031f
+
+#define LINUX_HDIO_SET_MULTCOUNT 0x0321
+#define LINUX_HDIO_SET_UNMASKINTR 0x0322
+#define LINUX_HDIO_SET_KEEPSETTINGS 0x0323
+#define LINUX_HDIO_SET_32BIT 0x0324
+#define LINUX_HDIO_SET_NOWERR 0x0325
+#define LINUX_HDIO_SET_DMA 0x0326
+#define LINUX_HDIO_SET_PIO_MODE 0x0327
+#define LINUX_HDIO_SCAN_HWIF 0x0328
+#define LINUX_HDIO_SET_NICE 0x0329
+#define LINUX_HDIO_UNREGISTER_HWIF 0x032a
+
+struct linux_hd_geometry {
+ u_char heads;
+ u_char sectors;
+ u_short cylinders;
+ u_long start;
+};
+
+struct linux_hd_big_geometry {
+ u_char heads;
+ u_char sectors;
+ u_int cylinders;
+ u_long start;
+};
+
+#endif /* _LINUX_HDIO_H */
diff --git a/sys/compat/linux/linux_ioctl.c b/sys/compat/linux/linux_ioctl.c
index 098e6412d46..204c01d0a8c 100644
--- a/sys/compat/linux/linux_ioctl.c
+++ b/sys/compat/linux/linux_ioctl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: linux_ioctl.c,v 1.8 2000/07/23 22:35:38 jasoni Exp $ */
+/* $OpenBSD: linux_ioctl.c,v 1.9 2001/04/09 06:53:45 tholo Exp $ */
/* $NetBSD: linux_ioctl.c,v 1.14 1996/04/05 00:01:28 christos Exp $ */
/*
@@ -78,12 +78,20 @@ linux_sys_ioctl(p, v, retval)
return oss_ioctl_sequencer(p, LINUX_TO_OSS(v), retval);
case 'P':
return oss_ioctl_audio(p, LINUX_TO_OSS(v), retval);
- case 'T':
+ case 't':
+ case 'f':
+ case 'T': /* XXX MIDI sequencer uses 'T' as well */
return linux_ioctl_termios(p, uap, retval);
case 'S':
return linux_ioctl_cdrom(p, uap, retval);
case 0x89:
return linux_ioctl_socket(p, uap, retval);
+ case 0x03:
+ return linux_ioctl_hdio(p, uap, retval);
+ case 0x02:
+ return linux_ioctl_fdio(p, uap, retval);
+ case 0x12:
+ return linux_ioctl_blkio(p, uap, retval);
default:
return linux_machdepioctl(p, uap, retval);
}
diff --git a/sys/compat/linux/linux_ioctl.h b/sys/compat/linux/linux_ioctl.h
index 8dbe87da0a6..5baa519a6b3 100644
--- a/sys/compat/linux/linux_ioctl.h
+++ b/sys/compat/linux/linux_ioctl.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: linux_ioctl.h,v 1.4 1997/12/07 22:59:15 provos Exp $ */
+/* $OpenBSD: linux_ioctl.h,v 1.5 2001/04/09 06:53:45 tholo Exp $ */
/* $NetBSD: linux_ioctl.h,v 1.4 1996/04/05 00:01:36 christos Exp $ */
/*
@@ -32,8 +32,51 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#define _LINUX_IO(x,y) (((x) << 8) | (y))
-#define LINUX_IOCGROUP(x) (((x) >> 8) & 0xff)
+#define _LINUX_IOC_NRBITS 8
+#define _LINUX_IOC_TYPEBITS 8
+#define _LINUX_IOC_SIZEBITS 14
+#define _LINUX_IOC_DIRBITS 2
+
+#define _LINUX_IOC_NRSHIFT 0
+
+#define _LINUX_IOC_NONE 0U
+#define _LINUX_IOC_WRITE 1U
+#define _LINUX_IOC_READ 2U
+
+#define _LINUX_IOC_NRMASK ((1 << _LINUX_IOC_NRBITS) - 1)
+#define _LINUX_IOC_TYPEMASK ((1 << _LINUX_IOC_TYPEBITS) - 1)
+#define _LINUX_IOC_SIZEMASK ((1 << _LINUX_IOC_SIZEBITS) - 1)
+#define _LINUX_IOC_DIRMASK ((1 << _LINUX_IOC_DIRBITS) - 1)
+
+#define _LINUX_IOC_TYPESHIFT (_LINUX_IOC_NRSHIFT + _LINUX_IOC_NRBITS)
+#define _LINUX_IOC_SIZESHIFT (_LINUX_IOC_TYPESHIFT + _LINUX_IOC_TYPEBITS)
+#define _LINUX_IOC_DIRSHIFT (_LINUX_IOC_SIZESHIFT + _LINUX_IOC_SIZEBITS)
+
+#define _LINUX_IOC(dir,type,nr,size) \
+ (((nr) << _LINUX_IOC_NRSHIFT) | \
+ ((type) << _LINUX_IOC_TYPESHIFT) | \
+ ((size) << _LINUX_IOC_SIZESHIFT) | \
+ ((dir) << _LINUX_IOC_DIRSHIFT))
+
+#define _LINUX_IO(type,nr) \
+ _LINUX_IOC(_LINUX_IOC_NONE,(type),(nr),0)
+#define _LINUX_IOR(type,nr,size) \
+ _LINUX_IOC(_LINUX_IOC_READ,(type),(nr),sizeof(size))
+#define _LINUX_IOW(type,nr,size) \
+ _LINUX_IOC(_LINUX_IOC_WRITE,(type),(nr),sizeof(size))
+#define _LINUX_IOWR(type,nr,size) \
+ _LINUX_IOC(_LINUX_IOC_READ|_LINUX_IOC_WRITE,(type),(nr),sizeof(size))
+
+#define _LINUX_IOC_DIR(nr) \
+ (((nr) >> _LINUX_IOC_DIRSHIFT) & _LINUX_IOC_DIRMASK)
+#define _LINUX_IOC_TYPE(nr) \
+ (((nr) >> _LINUX_IOC_TYPESHIFT) & _LINUX_IOC_TYPEMASK)
+#define _LINUX_IOC_NR(nr) \
+ (((nr) >> _LINUX_IOC_NRSHIFT) & _LINUX_IOC_NRMASK)
+#define _LINUX_IOC_SIZE(nr) \
+ (((nr) >> _LINUX_IOC_SIZESHIFT) & _LINUX_IOC_SIZEMASK)
+
+#define LINUX_IOCGROUP(x) _LINUX_IOC_TYPE(x)
struct linux_sys_ioctl_args;
int linux_ioctl_audio __P((struct proc *, struct linux_sys_ioctl_args *,
@@ -45,3 +88,9 @@ int linux_ioctl_cdrom __P((struct proc *, struct linux_sys_ioctl_args *,
register_t *));
int linux_ioctl_socket __P((struct proc *, struct linux_sys_ioctl_args *,
register_t *));
+int linux_ioctl_hdio __P((struct proc *, struct linux_sys_ioctl_args *,
+ register_t *));
+int linux_ioctl_fdio __P((struct proc *, struct linux_sys_ioctl_args *,
+ register_t *));
+int linux_ioctl_blkio __P((struct proc *, struct linux_sys_ioctl_args *,
+ register_t *));