NetBSD/sys/lib/libsa/ioctl.c

96 lines
3.5 KiB
C
Raw Normal View History

2000-03-30 16:19:46 +04:00
/* $NetBSD: ioctl.c,v 1.6 2000/03/30 12:19:48 augustss Exp $ */
1994-10-26 08:44:32 +03:00
1994-01-26 05:03:32 +03:00
/*-
* Copyright (c) 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* The Mach Operating System project at Carnegie-Mellon University.
*
* 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 by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 THE REGENTS OR CONTRIBUTORS 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.
*
1994-10-26 08:44:32 +03:00
* @(#)ioctl.c 8.1 (Berkeley) 6/11/93
1994-01-26 05:03:32 +03:00
*
*
* Copyright (c) 1989, 1990, 1991 Carnegie Mellon University
* All Rights Reserved.
*
* Author: Alessandro Forin
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie the
* rights to redistribute these changes.
*/
#include "stand.h"
int
1994-01-26 05:03:32 +03:00
ioctl(fd, cmd, arg)
int fd;
u_long cmd;
1994-01-26 05:03:32 +03:00
char *arg;
{
Make a bunch of backward-compatible changes to the boot blocks which allow size to be reduced substantially. (backward compatibility verified by compiling one of the alpha boot blocks which uses all of the code before and after, diffing the object files, and manually verifying that the differences were 'correct'. some differences were "unavoidable," it wanting to avoid a double-commit, because e.g. local variables which were previously used were no longer used.) a README which describes supported options (or at least the ones mentioned below) is forthcoming. add support for the preprocessor macro LIBSA_NO_TWIDDLE, which causes calls to twiddle() to be omitted if it's defined. add support for the preprocessor macros: LIBSA_NO_FS_CLOSE LIBSA_NO_FS_WRITE LIBSA_NO_FS_SEEK which, if defined, cause the corresponding file system operations in the individual file system implementations to be omitted. (note that all of those macros are not supported by all file systems at this point. comments were added to individual file system files to indicate lack of support, and should be cleaned up later. Backward compatibility options e.g. UFS_NOCLOSE, etc., are supported.) add support for the preprocessor macro LIBSA_NO_FS_SYMLINK, which removes support for symbolic links from the file system support functions. (same notes as for the macros above apply.) add support for the preprocessor macro LIBSA_FS_SINGLECOMPONENT which removes all subdirectory and symlink support from the file system support functions. (same notes as for the macros above apply.) add support for the preprocessor macro LIBSA_NO_FD_CHECKING, which causes code relating to libsa file descriptor checks (e.g. range checking and checking that a file descriptor is valid) to be omitted if it's defined. add support for the preprocessor macro LIBSA_NO_RAW_ACCESS, which causes code relating to raw device access to be omitted if it's defined. change some structure copies to use bcopy() instead. that way use of bcopy vs. memcpy() can easily be selected by LIBSA_USE_MEMCPY. (without changes like these, you could end up having both bcopy() and memcpy() included. eventually, all calls to bcopy should be changed to calls to memcpy() or memmove() as appropriate -- hopefully never the latter -- with an option to use bcopy instead.) add support for the preprocessor macro LIBSA_NO_DISKLABEL_MSGS, which causes disklabel() to return '1' as msg rather than a string. Can be used if the boot blocks don't care about the string, and need to save the space. add support for the preprocessor macro LIBSA_SINGLE_FILESYSTEM, which if defined causes all of the file system switch code to be removed. Its value should be the name of the file system supported by the boot block, e.g. "ufs" for the FFS file system. calls to the file system functions open, close, etc., which were previously done through a function switch are then done via direct invocation of <fs>_open, <fs>_close, etc. (e.g. ufs_open, ...). add support for the preprocessor macro LIBSA_SINGLE_DEVICE, which does the equivalent of LIBSA_SINGLE_FILESYSTEM but for the device switch table. Device entry pointes are expected to be named <dev>foo, e.g. the 'strategy' routine used when LIBSA_SINGLE_DEVICE is set to 'disk' is diskstrategy. make ufs.c f_nindir array be unsigned ints. the fact that it was signed caused ufs.c to require signed division routines (which were otherwise unnecessary for a small boot block).
1999-03-31 05:50:25 +04:00
#if !defined(LIBSA_NO_FD_CHECKING) || !defined(LIBSA_NO_RAW_ACCESS)
2000-03-30 16:19:46 +04:00
struct open_file *f = &files[fd];
Make a bunch of backward-compatible changes to the boot blocks which allow size to be reduced substantially. (backward compatibility verified by compiling one of the alpha boot blocks which uses all of the code before and after, diffing the object files, and manually verifying that the differences were 'correct'. some differences were "unavoidable," it wanting to avoid a double-commit, because e.g. local variables which were previously used were no longer used.) a README which describes supported options (or at least the ones mentioned below) is forthcoming. add support for the preprocessor macro LIBSA_NO_TWIDDLE, which causes calls to twiddle() to be omitted if it's defined. add support for the preprocessor macros: LIBSA_NO_FS_CLOSE LIBSA_NO_FS_WRITE LIBSA_NO_FS_SEEK which, if defined, cause the corresponding file system operations in the individual file system implementations to be omitted. (note that all of those macros are not supported by all file systems at this point. comments were added to individual file system files to indicate lack of support, and should be cleaned up later. Backward compatibility options e.g. UFS_NOCLOSE, etc., are supported.) add support for the preprocessor macro LIBSA_NO_FS_SYMLINK, which removes support for symbolic links from the file system support functions. (same notes as for the macros above apply.) add support for the preprocessor macro LIBSA_FS_SINGLECOMPONENT which removes all subdirectory and symlink support from the file system support functions. (same notes as for the macros above apply.) add support for the preprocessor macro LIBSA_NO_FD_CHECKING, which causes code relating to libsa file descriptor checks (e.g. range checking and checking that a file descriptor is valid) to be omitted if it's defined. add support for the preprocessor macro LIBSA_NO_RAW_ACCESS, which causes code relating to raw device access to be omitted if it's defined. change some structure copies to use bcopy() instead. that way use of bcopy vs. memcpy() can easily be selected by LIBSA_USE_MEMCPY. (without changes like these, you could end up having both bcopy() and memcpy() included. eventually, all calls to bcopy should be changed to calls to memcpy() or memmove() as appropriate -- hopefully never the latter -- with an option to use bcopy instead.) add support for the preprocessor macro LIBSA_NO_DISKLABEL_MSGS, which causes disklabel() to return '1' as msg rather than a string. Can be used if the boot blocks don't care about the string, and need to save the space. add support for the preprocessor macro LIBSA_SINGLE_FILESYSTEM, which if defined causes all of the file system switch code to be removed. Its value should be the name of the file system supported by the boot block, e.g. "ufs" for the FFS file system. calls to the file system functions open, close, etc., which were previously done through a function switch are then done via direct invocation of <fs>_open, <fs>_close, etc. (e.g. ufs_open, ...). add support for the preprocessor macro LIBSA_SINGLE_DEVICE, which does the equivalent of LIBSA_SINGLE_FILESYSTEM but for the device switch table. Device entry pointes are expected to be named <dev>foo, e.g. the 'strategy' routine used when LIBSA_SINGLE_DEVICE is set to 'disk' is diskstrategy. make ufs.c f_nindir array be unsigned ints. the fact that it was signed caused ufs.c to require signed division routines (which were otherwise unnecessary for a small boot block).
1999-03-31 05:50:25 +04:00
#endif
1994-01-26 05:03:32 +03:00
Make a bunch of backward-compatible changes to the boot blocks which allow size to be reduced substantially. (backward compatibility verified by compiling one of the alpha boot blocks which uses all of the code before and after, diffing the object files, and manually verifying that the differences were 'correct'. some differences were "unavoidable," it wanting to avoid a double-commit, because e.g. local variables which were previously used were no longer used.) a README which describes supported options (or at least the ones mentioned below) is forthcoming. add support for the preprocessor macro LIBSA_NO_TWIDDLE, which causes calls to twiddle() to be omitted if it's defined. add support for the preprocessor macros: LIBSA_NO_FS_CLOSE LIBSA_NO_FS_WRITE LIBSA_NO_FS_SEEK which, if defined, cause the corresponding file system operations in the individual file system implementations to be omitted. (note that all of those macros are not supported by all file systems at this point. comments were added to individual file system files to indicate lack of support, and should be cleaned up later. Backward compatibility options e.g. UFS_NOCLOSE, etc., are supported.) add support for the preprocessor macro LIBSA_NO_FS_SYMLINK, which removes support for symbolic links from the file system support functions. (same notes as for the macros above apply.) add support for the preprocessor macro LIBSA_FS_SINGLECOMPONENT which removes all subdirectory and symlink support from the file system support functions. (same notes as for the macros above apply.) add support for the preprocessor macro LIBSA_NO_FD_CHECKING, which causes code relating to libsa file descriptor checks (e.g. range checking and checking that a file descriptor is valid) to be omitted if it's defined. add support for the preprocessor macro LIBSA_NO_RAW_ACCESS, which causes code relating to raw device access to be omitted if it's defined. change some structure copies to use bcopy() instead. that way use of bcopy vs. memcpy() can easily be selected by LIBSA_USE_MEMCPY. (without changes like these, you could end up having both bcopy() and memcpy() included. eventually, all calls to bcopy should be changed to calls to memcpy() or memmove() as appropriate -- hopefully never the latter -- with an option to use bcopy instead.) add support for the preprocessor macro LIBSA_NO_DISKLABEL_MSGS, which causes disklabel() to return '1' as msg rather than a string. Can be used if the boot blocks don't care about the string, and need to save the space. add support for the preprocessor macro LIBSA_SINGLE_FILESYSTEM, which if defined causes all of the file system switch code to be removed. Its value should be the name of the file system supported by the boot block, e.g. "ufs" for the FFS file system. calls to the file system functions open, close, etc., which were previously done through a function switch are then done via direct invocation of <fs>_open, <fs>_close, etc. (e.g. ufs_open, ...). add support for the preprocessor macro LIBSA_SINGLE_DEVICE, which does the equivalent of LIBSA_SINGLE_FILESYSTEM but for the device switch table. Device entry pointes are expected to be named <dev>foo, e.g. the 'strategy' routine used when LIBSA_SINGLE_DEVICE is set to 'disk' is diskstrategy. make ufs.c f_nindir array be unsigned ints. the fact that it was signed caused ufs.c to require signed division routines (which were otherwise unnecessary for a small boot block).
1999-03-31 05:50:25 +04:00
#if !defined(LIBSA_NO_FD_CHECKING)
1994-01-26 05:03:32 +03:00
if ((unsigned)fd >= SOPEN_MAX || f->f_flags == 0) {
errno = EBADF;
return (-1);
}
Make a bunch of backward-compatible changes to the boot blocks which allow size to be reduced substantially. (backward compatibility verified by compiling one of the alpha boot blocks which uses all of the code before and after, diffing the object files, and manually verifying that the differences were 'correct'. some differences were "unavoidable," it wanting to avoid a double-commit, because e.g. local variables which were previously used were no longer used.) a README which describes supported options (or at least the ones mentioned below) is forthcoming. add support for the preprocessor macro LIBSA_NO_TWIDDLE, which causes calls to twiddle() to be omitted if it's defined. add support for the preprocessor macros: LIBSA_NO_FS_CLOSE LIBSA_NO_FS_WRITE LIBSA_NO_FS_SEEK which, if defined, cause the corresponding file system operations in the individual file system implementations to be omitted. (note that all of those macros are not supported by all file systems at this point. comments were added to individual file system files to indicate lack of support, and should be cleaned up later. Backward compatibility options e.g. UFS_NOCLOSE, etc., are supported.) add support for the preprocessor macro LIBSA_NO_FS_SYMLINK, which removes support for symbolic links from the file system support functions. (same notes as for the macros above apply.) add support for the preprocessor macro LIBSA_FS_SINGLECOMPONENT which removes all subdirectory and symlink support from the file system support functions. (same notes as for the macros above apply.) add support for the preprocessor macro LIBSA_NO_FD_CHECKING, which causes code relating to libsa file descriptor checks (e.g. range checking and checking that a file descriptor is valid) to be omitted if it's defined. add support for the preprocessor macro LIBSA_NO_RAW_ACCESS, which causes code relating to raw device access to be omitted if it's defined. change some structure copies to use bcopy() instead. that way use of bcopy vs. memcpy() can easily be selected by LIBSA_USE_MEMCPY. (without changes like these, you could end up having both bcopy() and memcpy() included. eventually, all calls to bcopy should be changed to calls to memcpy() or memmove() as appropriate -- hopefully never the latter -- with an option to use bcopy instead.) add support for the preprocessor macro LIBSA_NO_DISKLABEL_MSGS, which causes disklabel() to return '1' as msg rather than a string. Can be used if the boot blocks don't care about the string, and need to save the space. add support for the preprocessor macro LIBSA_SINGLE_FILESYSTEM, which if defined causes all of the file system switch code to be removed. Its value should be the name of the file system supported by the boot block, e.g. "ufs" for the FFS file system. calls to the file system functions open, close, etc., which were previously done through a function switch are then done via direct invocation of <fs>_open, <fs>_close, etc. (e.g. ufs_open, ...). add support for the preprocessor macro LIBSA_SINGLE_DEVICE, which does the equivalent of LIBSA_SINGLE_FILESYSTEM but for the device switch table. Device entry pointes are expected to be named <dev>foo, e.g. the 'strategy' routine used when LIBSA_SINGLE_DEVICE is set to 'disk' is diskstrategy. make ufs.c f_nindir array be unsigned ints. the fact that it was signed caused ufs.c to require signed division routines (which were otherwise unnecessary for a small boot block).
1999-03-31 05:50:25 +04:00
#endif
#if !defined(LIBSA_NO_RAW_ACCESS)
1994-01-26 05:03:32 +03:00
if (f->f_flags & F_RAW) {
Make a bunch of backward-compatible changes to the boot blocks which allow size to be reduced substantially. (backward compatibility verified by compiling one of the alpha boot blocks which uses all of the code before and after, diffing the object files, and manually verifying that the differences were 'correct'. some differences were "unavoidable," it wanting to avoid a double-commit, because e.g. local variables which were previously used were no longer used.) a README which describes supported options (or at least the ones mentioned below) is forthcoming. add support for the preprocessor macro LIBSA_NO_TWIDDLE, which causes calls to twiddle() to be omitted if it's defined. add support for the preprocessor macros: LIBSA_NO_FS_CLOSE LIBSA_NO_FS_WRITE LIBSA_NO_FS_SEEK which, if defined, cause the corresponding file system operations in the individual file system implementations to be omitted. (note that all of those macros are not supported by all file systems at this point. comments were added to individual file system files to indicate lack of support, and should be cleaned up later. Backward compatibility options e.g. UFS_NOCLOSE, etc., are supported.) add support for the preprocessor macro LIBSA_NO_FS_SYMLINK, which removes support for symbolic links from the file system support functions. (same notes as for the macros above apply.) add support for the preprocessor macro LIBSA_FS_SINGLECOMPONENT which removes all subdirectory and symlink support from the file system support functions. (same notes as for the macros above apply.) add support for the preprocessor macro LIBSA_NO_FD_CHECKING, which causes code relating to libsa file descriptor checks (e.g. range checking and checking that a file descriptor is valid) to be omitted if it's defined. add support for the preprocessor macro LIBSA_NO_RAW_ACCESS, which causes code relating to raw device access to be omitted if it's defined. change some structure copies to use bcopy() instead. that way use of bcopy vs. memcpy() can easily be selected by LIBSA_USE_MEMCPY. (without changes like these, you could end up having both bcopy() and memcpy() included. eventually, all calls to bcopy should be changed to calls to memcpy() or memmove() as appropriate -- hopefully never the latter -- with an option to use bcopy instead.) add support for the preprocessor macro LIBSA_NO_DISKLABEL_MSGS, which causes disklabel() to return '1' as msg rather than a string. Can be used if the boot blocks don't care about the string, and need to save the space. add support for the preprocessor macro LIBSA_SINGLE_FILESYSTEM, which if defined causes all of the file system switch code to be removed. Its value should be the name of the file system supported by the boot block, e.g. "ufs" for the FFS file system. calls to the file system functions open, close, etc., which were previously done through a function switch are then done via direct invocation of <fs>_open, <fs>_close, etc. (e.g. ufs_open, ...). add support for the preprocessor macro LIBSA_SINGLE_DEVICE, which does the equivalent of LIBSA_SINGLE_FILESYSTEM but for the device switch table. Device entry pointes are expected to be named <dev>foo, e.g. the 'strategy' routine used when LIBSA_SINGLE_DEVICE is set to 'disk' is diskstrategy. make ufs.c f_nindir array be unsigned ints. the fact that it was signed caused ufs.c to require signed division routines (which were otherwise unnecessary for a small boot block).
1999-03-31 05:50:25 +04:00
errno = DEV_IOCTL(f->f_dev)(f, cmd, arg);
1994-01-26 05:03:32 +03:00
if (errno)
return (-1);
return (0);
}
Make a bunch of backward-compatible changes to the boot blocks which allow size to be reduced substantially. (backward compatibility verified by compiling one of the alpha boot blocks which uses all of the code before and after, diffing the object files, and manually verifying that the differences were 'correct'. some differences were "unavoidable," it wanting to avoid a double-commit, because e.g. local variables which were previously used were no longer used.) a README which describes supported options (or at least the ones mentioned below) is forthcoming. add support for the preprocessor macro LIBSA_NO_TWIDDLE, which causes calls to twiddle() to be omitted if it's defined. add support for the preprocessor macros: LIBSA_NO_FS_CLOSE LIBSA_NO_FS_WRITE LIBSA_NO_FS_SEEK which, if defined, cause the corresponding file system operations in the individual file system implementations to be omitted. (note that all of those macros are not supported by all file systems at this point. comments were added to individual file system files to indicate lack of support, and should be cleaned up later. Backward compatibility options e.g. UFS_NOCLOSE, etc., are supported.) add support for the preprocessor macro LIBSA_NO_FS_SYMLINK, which removes support for symbolic links from the file system support functions. (same notes as for the macros above apply.) add support for the preprocessor macro LIBSA_FS_SINGLECOMPONENT which removes all subdirectory and symlink support from the file system support functions. (same notes as for the macros above apply.) add support for the preprocessor macro LIBSA_NO_FD_CHECKING, which causes code relating to libsa file descriptor checks (e.g. range checking and checking that a file descriptor is valid) to be omitted if it's defined. add support for the preprocessor macro LIBSA_NO_RAW_ACCESS, which causes code relating to raw device access to be omitted if it's defined. change some structure copies to use bcopy() instead. that way use of bcopy vs. memcpy() can easily be selected by LIBSA_USE_MEMCPY. (without changes like these, you could end up having both bcopy() and memcpy() included. eventually, all calls to bcopy should be changed to calls to memcpy() or memmove() as appropriate -- hopefully never the latter -- with an option to use bcopy instead.) add support for the preprocessor macro LIBSA_NO_DISKLABEL_MSGS, which causes disklabel() to return '1' as msg rather than a string. Can be used if the boot blocks don't care about the string, and need to save the space. add support for the preprocessor macro LIBSA_SINGLE_FILESYSTEM, which if defined causes all of the file system switch code to be removed. Its value should be the name of the file system supported by the boot block, e.g. "ufs" for the FFS file system. calls to the file system functions open, close, etc., which were previously done through a function switch are then done via direct invocation of <fs>_open, <fs>_close, etc. (e.g. ufs_open, ...). add support for the preprocessor macro LIBSA_SINGLE_DEVICE, which does the equivalent of LIBSA_SINGLE_FILESYSTEM but for the device switch table. Device entry pointes are expected to be named <dev>foo, e.g. the 'strategy' routine used when LIBSA_SINGLE_DEVICE is set to 'disk' is diskstrategy. make ufs.c f_nindir array be unsigned ints. the fact that it was signed caused ufs.c to require signed division routines (which were otherwise unnecessary for a small boot block).
1999-03-31 05:50:25 +04:00
#endif
errno = EIO;
1994-01-26 05:03:32 +03:00
return (-1);
}